我刚刚在 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/