[英]Connect Parse Server iOS swift app to Heroku
I've setup an heroku account with the following credentials : 我已经使用以下凭据设置了一个heroku帐户:
and the following is my index.js setup : 以下是我的index.js设置:
var express = require('express'); // find this line in the file
var cors = require('cors') // add this line below it
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI ;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://heroku_vpgrmmf2:xxx@xxx.mlab.com:53735/heroku_vpgrmmf2',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || '',
masterKey: process.env.MASTER_KEY || '',
serverURL: process.env.SERVER_URL || 'https://myapp.herokuapp.com/parse',
clientKey: process.env.CLIENT_KEY || '',
javascriptKey: process.env.JAVASCRIPT_KEY || '',
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
var app = express();
app.use(cors());
Obviously filled in with the same credentials as the Heroku server. 显然填充了与Heroku服务器相同的凭据。 I've tested it on this page and it seems to be working : I get the following message 我已经在此页面上对其进行了测试,并且似乎可以正常使用:我收到以下消息
However, when I run my swift app with this setup for the app delegate : 但是,当我使用此设置为应用程序委托运行swift应用程序时:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Parse.enableLocalDatastore() let configuration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in ParseMutableClientConfiguration.applicationId = "" ParseMutableClientConfiguration.clientKey = "" ParseMutableClientConfiguration.server = " https://myapp.herokuapp.com/parse " }) func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?)->布尔{Parse.enableLocalDatastore()let configuration = ParseClientConfiguration(block:{(ParseMutableClientConfiguration)-> ParseMutableClientConfiguration.applicationId =“ Vose在ParseMutableClientConfiguration。 clientKey =“” ParseMutableClientConfiguration.server =“ https://myapp.herokuapp.com/parse ”})
// Swift 3.0
Parse.initialize(with: configuration)
Parse.setApplicationId("", clientKey: "")
PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions)
PFUser.enableAutomaticUser()
let defaultACL = PFACL();
defaultACL.getPublicReadAccess = true
PFACL.setDefault(defaultACL, withAccessForCurrentUser: true)
if application.applicationState != UIApplicationState.background {
let preBackgroundPush = !application.responds(to: #selector(getter: UIApplication.backgroundRefreshStatus))
let oldPushHandlerOnly = !self.responds(to: #selector(UIApplicationDelegate.application(_:didReceiveRemoteNotification:fetchCompletionHandler:)))
var noPushPayload = false;
if let options = launchOptions {
noPushPayload = options[UIApplicationLaunchOptionsKey.remoteNotification] != nil;
}
if (preBackgroundPush || oldPushHandlerOnly || noPushPayload) {
PFAnalytics.trackAppOpened(launchOptions: launchOptions)
}
}
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)}
(obviously filled with the right credentials too). (显然也填充了正确的凭据)。 It doesn't seem to be connected to the server as I get this error : 由于出现此错误,它似乎未连接到服务器:
I've been trying to figure out what am I doing wrong for the past week but I wasn't able to. 我一直在努力弄清过去一周我在做什么错,但我没有能力。 Does anybody have any idea of what I could be doing wrong? 有人知道我可能做错了什么吗? Thanks in advance. 提前致谢。
EDIT: Also, this is the code I added to my info.plist file : 编辑:另外,这是我添加到我的info.plist文件中的代码:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>myapp.herokuapp.com/parse</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSRequiresCertificateTransparency</key>
<string></string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<false/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
</dict>
</dict>
I eventually figured it out : I had to delete this line from the appDelegate : 我最终弄清楚了:我不得不从appDelegate删除此行:
Parse.setApplicationId("myappid", clientKey: "myclientkey")
And now it works, not sure why but I'm glad. 现在它可以工作了,不知道为什么,但是我很高兴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.