我正在现有的Mac OS X应用程序中尝试Parse SDK。我按照Parse快速入门指南中的设置步骤进行操作,包括将Parse库的导入添加到我的AppDelegate .m文件并调用:
[Parse setApplicationId:kParseApplicationID clientKey:kParseClientKey];
在applicationDidFinishLaunching方法中。我使用的两个常量在Constants文件中定义,该文件也是导入的。
导航结束时说:“然后将此代码复制并粘贴到您的应用中,例如在viewDidLoad方法中(或在运行应用时调用的另一个方法内)”
因此,我将Parse头文件导入到我的主视图控制器.m文件中,并将其代码复制并粘贴到其viewDidLoad方法中:
PFObject *testObject = [PFObject objectWithClassName:@"TestObject"];
testObject[@"foo"] = @"bar";
[testObject saveInBackground];
当它运行时,我在最后一行上遇到了一个异常,其消息是“setObjectForKey:key不能为nil”。不是在我实际设置密钥对象的前一行。此外,如果我停在前一行和PO testObject,testObject.allKeys或testObject [@“foo”],它们都会显示键“foo”的非零值。此外,如果我将此代码移动到AppDelegate的applicationDidFinishLaunching方法的末尾,代码将执行而不会出现任何错误,并且TestObject会显示在我的Parse应用程序仪表板中。
有人可以告诉我我做错了什么吗?我真的想进一步探索,但这对我来说是一个真正的阻碍。
这是来自稍微更多参与的OS X应用程序的控制台日志,也发生在[ParseObject saveInBackgroundWithBlock:]上:
2015-06-03 16:55:56.046 TestApp [15795:15954566] An uncaught exception was raised
2015-06-03 16:55:56.046 TestApp [15795:15954566] *** setObjectForKey: key cannot be nil
2015-06-03 16:55:56.046 TestApp [15795:15954566] (
0 CoreFoundation 0x00007fff8fb0103c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff978e476e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8f9e7c66 -[__NSDictionaryM setObject:forKey:] + 1174
3 ParseOSX 0x000000010011adbb __74-[PFMultiProcessFileLockController beginLockedContentAccessForFileAtPath:]_block_invoke + 129
4 libdispatch.dylib 0x000000010026cd43 _dispatch_client_callout + 8
5 libdispatch.dylib 0x000000010026e0b1 _dispatch_barrier_sync_f_invoke + 348
6 ParseOSX 0x000000010011ad15 -[PFMultiProcessFileLockController beginLockedContentAccessForFileAtPath:] + 127
7 ParseOSX 0x00000001000f61ea +[PFObject(Private) _objectFromDataFile:error:] + 207
8 ParseOSX 0x000000010010f231 +[PFUser(Private) _getCurrentUserWithOptions:] + 611
9 ParseOSX 0x00000001000fc4bd -[PFObject(Private) saveAsync:] + 118
10 ParseOSX 0x00000001000e1d25 -[PFTaskQueue enqueue:] + 188
11 ParseOSX 0x00000001000ff06b -[PFObject saveInBackground] + 121
12 ParseOSX 0x00000001000ff270 -[PFObject saveInBackgroundWithBlock:] + 49
13 TestApp 0x0000000100001827 +[SBTParseTranslation saveDBObjectToParse:] + 183
14 TestApp 0x0000000100031fb4 -[SWBMainWindowViewController showRecordForItem:] + 3124
15 TestApp 0x0000000100031268 -[SWBMainWindowViewController showRecordForID:] + 184
16 TestApp 0x0000000100031080 -[SWBMainWindowViewController finishLoad] + 448
17 TestApp 0x0000000100030eb1 -[SWBMainWindowViewController loadData] + 97
18 TestApp 0x0000000100030dd5 -[SWBMainWindowViewController viewDidLoad] + 725
答案 0 :(得分:0)
这是由于我的混淆造成的。我主要在iOS项目上工作,其中applicationDidFinishLaunching通常可以指望在viewControllers加载之前运行。显然,OS X应用程序并非如此。
简而言之,我在调用[Parse setApplicationID:clientKey]之前调用了ParseObject保存方法。
答案 1 :(得分:0)
In my case ios7 was crashing with saveInBackground since podfile contained:
platform :ios, '8.0'
and deployment target was 7.0. I replaced with
platform :ios, '7.0'
then clean and build again