ios - 对象未保存在 Parse-Server 上

标签 ios objective-c heroku parse-server

我刚刚在 Parse-Server (Heroku/MLab) 上设置了一个应用程序以与 iOS 应用程序(在 Objective-C 中)一起使用。 引用我之前的几次此类经历,我觉得应该是可以的。但是当我尝试将一个对象从我的 iOS 应用程序保存到 Parse-Server 时,它失败了。

这是 AppDelegate.m 中的初始化代码:

[Parse initializeWithConfiguration:
 [ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
    configuration.applicationId = @"AAAABBBCCCCXXXXYYYY333344445555";
    configuration.clientKey = @"9999999888888887777777wwwwwwHHHHHHzzzzZZZ";
    configuration.localDatastoreEnabled = @"https://myownapp.herokuapp.com/parse";
}]];

这是我用来在 iOS 应用程序中保存对象的代码:

PFObject *myObject = [PFObject objectWithClassName:@"MyCollectionName"];
// name and membersString are NSString objects previously defined.
myObject[@"name"] = name; 
myObject[@"members"] = membersString;
[myObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
    if (succeeded) {
        NSLog(@"all is working fine!");
    } else {
        NSLog(@"Error:\n%@",error);
    }
}];

这是我在 Xcode 调试控制台中得到的错误:

Error Domain=Parse Code=100 "A server with the specified hostname could not be found." 
UserInfo={code=100, error=A server with the specified hostname could not be found., 
NSLocalizedDescription=A server with the specified hostname could not be found., 
temporary=1, originalError=Error Domain=NSURLErrorDomain 
Code=-1003 "A server with the specified hostname could not be found." 
UserInfo={NSUnderlyingError=0x1c0844140 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" 
UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, 
NSErrorFailingURLStringKey=https://api.parse.com/1/classes/MyCollectionName, 
NSErrorFailingURLKey=https://api.parse.com/1/classes/MyCollectionName, 
_kCFStreamErrorDomainKey=12, _kCFStreamErrorCodeKey=8, 
NSLocalizedDescription=A server with the specified hostname could not be found.}, 
NSUnderlyingError=0x1c0848b20 {Error Domain=NSURLErrorDomain 
Code=-1003 "A server with the specified hostname could not be found." 
UserInfo={NSUnderlyingError=0x1c0844140 {Error Domain=kCFErrorDomainCFNetwork 
Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, 
NSErrorFailingURLStringKey=https://api.parse.com/1/classes/MyCollectionName, 
NSErrorFailingURLKey=https://api.parse.com/1/classes/MyCollectionName, _kCFStreamErrorDomainKey=12, 
_kCFStreamErrorCodeKey=8, NSLocalizedDescription=A server with the specified hostname could not be found.}}}

我已经为我的服务器设置了一个专有名称:https://myownapp.herokuapp.com/ .

我不太明白为什么我会看到:https://api.parse.com出现在错误信息中。 这可能是哪里出了问题?但我真的不知道该怎么做才能改变它。 我想我已经在应用程序端和服务器端完成了所有必要的工作;但我显然遗漏了一些东西。

如果有人对解决方案有任何想法,请告诉我。我们将不胜感激。

最佳答案

您可能需要正确初始化 SDK。

configuration.localDatastoreEnabled = @"https://myownapp.herokuapp.com/parse";

这可能应该是:

configuration.server = @"https://myownapp.herokuapp.com/parse";
configuration.localDatastoreEnabled = true;

关于ios - 对象未保存在 Parse-Server 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48260213/

相关文章:

ios - 多步生成贝塞尔正方形

ios - Swift3:如何在 NSArray 中使用用户默认数据?

ios - 如何在 'Type to Siri'模式下调试Siri扩展?

iphone - 使用 Alpha 设置为 subview 添加背景色

ruby-on-rails - 通过 Heroku Rails 应用程序使用 DNS 和 SMTP 检查进行电子邮件验证

ios - 如何提取文本中的电子邮件/邮箱字符串列表或测试字符串是否为正确的电子邮件地址?

objective-c - 使用 for..in 逐行读取文件

ios - 将 Objective-C 框架 (CocoaPod) 导入 Swift?

javascript - 同时运行 Express 和 Create-React-App 问题

java - 如何将 telegram 机器人从 intellij 部署到 heroku?我使用 Maven 项目中的 Java 编写代码