LoginSignup
24
24

More than 5 years have passed since last update.

Parse Server - Heroku ディプロイ編

Last updated at Posted at 2016-02-06

MBaasのParseが2017年1月28日をもってサービスを終了することになりましたね。ただし、App側のSDKに加えバックエンドのParse Serverもオープンソース化されましたので、ミグレーションガイドに従い自前でサーバーを立てれば、サービス終了後も自力で継続することは可能です。細かいところはミグレーションガイドを参照していただくとして、稼働中のデータ移行を除けば、Paas/IaaSなどでサーバーを立てアプリ側をそちらにアクセスするように設定を切り替えるだけで作業は完了です。

とりあえずサンプルのParse Serverを敷居も低く無料で始められるHerokuへディプロイしてみたので、いくつか気付いたことを載せておきます。

1. Parse Server Example ディプロイ

息込んで書き始めてしまいましたが、Githubページにある"Deploy to Heroku"ボタンをクリックして指示に従うのみで、Deploying a Parse Server to Herokuの記載の通りです。サンプルといいつつ、自分のアプリ向けにいっさい手を加えずそのまま使えます。ちなみに1アプリにつき1サーバー立てる感じです。curlを投げてresultが返って来ればおk。

2. アプリ側でサーバー設定

普通にParseのバックエンドを利用していたアプリを、明示的にサーバーを指定するように変更します。

AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    ...

    // Parse.setApplicationId("YourParseApplicationId", clientKey: "YourParseClientKey")
    Parse.initializeWithConfiguration(ParseClientConfiguration { configuration in
        configuration.applicationId = "YourParseApplicationId"
        configuration.clientKey = "YourParseClientKey"
        configuration.server = "https://your-parse-server.herokuapp.com/parse"
    })
    ...
}

ちなみに、ParseClientConfigurationクラスでサーバー指定がコミットされたのは今年に入ってからなので、SDKは最新版でないと対応していないと思います。V4にまつわるもろもろを先延ばしにしていたアプリの場合、まずはSDKのバージョンアップ対応からですね。

いくつか問題がでて対処しましたので、参考までに載せておきます。

Facebookログインに失敗する。

[Error]: Facebook auth is not configured. (Code: 101, Version: 1.12.0)

Heroku側にもFacebookAppIDを設定する必要があります。

heroku config:set FACEBOOK_APP_ID=your-facebook-app-id --app your-heroku-app-name

PFUserのサブクラスが登録されていない。

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 
'The class YourUserSubClass must be registered with registerSubclass before using Parse.'

今風のSubclassはNSObject#initialize()をオーバーライドしていて問題ないと思いますが、PFUserのSubclassはGuideに記述もなく実行しても怒られることもなかったのでregisterSubclassしてませんでした。自分は古風にdidFinishLaunchingWithOptionsでYourUserSubClass.registerSubclass()を呼びましたが、以下でよいと思います。

override class func initialize() {
    struct Static {
      static var onceToken : dispatch_once_t = 0;
    }
    dispatch_once(&Static.onceToken) {
      self.registerSubclass()
    }
}

24
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
24