gpt4 book ai didi

ios - 将 Parse Server iOS swift 应用程序连接到 Heroku

转载 作者:行者123 更新时间:2023-11-30 12:42:53 26 4
gpt4 key购买 nike

我已经使用以下凭据设置了一个 heroku 帐户: heroku credentials

以下是我的 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());

显然填写了与 Heroku 服务器相同的凭据。我已经在 this 上测试过它页面,它似乎正在工作:我收到以下消息

test

但是,当我使用应用程序委托(delegate)的此设置运行我的 swift 应用程序时:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Parse.enableLocalDatastore() 让配置 = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> 无效 ParseMutableClientConfiguration.applicationId = "" 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)}

(显然也填写了正确的凭据)。当我收到此错误时,它似乎没有连接到服务器:

error

我一直试图找出过去一周我做错了什么,但我没能做到。有人知道我可能做错了什么吗?提前致谢。

编辑:另外,这是我添加到 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>

最佳答案

我最终想通了:我必须从 appDelegate 中删除这一行:

Parse.setApplicationId("myappid", clientKey: "myclientkey")

现在它可以工作了,不知道为什么,但我很高兴。

关于ios - 将 Parse Server iOS swift 应用程序连接到 Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42034047/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com