ios - 解析取消订阅 channel iOS 不工作

标签 ios parse-platform

我正尝试从通知 channel 取消订阅解析应用程序,但我的应用程序崩溃了。

这是我的有问题的应用程序代码:

- (IBAction)genb:(id)sender {
    NSArray *subscribedChannels = [PFInstallation currentInstallation].channels;
    if (![subscribedChannels containsObject:@"gen"]) {
        PFInstallation *currentInstallation = [PFInstallation currentInstallation];
        [currentInstallation addUniqueObject:@"gen" forKey:@"channels"];
        [currentInstallation saveInBackground];
        genl.text = @"Subscribed";
        [gen setTitle:@"Unsubscribe" forState:UIControlStateNormal];
    } else {
        PFInstallation *currentInstallation = [PFInstallation currentInstallation];
        [currentInstallation removeObject:@"gen" forKey:@"channels"];
        [currentInstallation saveInBackground];
        genl.text = @"Not Subscribed";
        [gen setTitle:@"Subscribe" forState:UIControlStateNormal];
    }
}

这是我的日志:

2014-04-26 21:51:28.388 Sulphur Public Schools[5338:3b03] Error: Error Domain=com.parse.networking.error Code=-1011 "Expected status code in (200-299), got 401" UserInfo=0x113ca50d0 {NSLocalizedDescription=Expected status code in (200-299), got 401, NSErrorFailingURLKey=https://api.parse.com/2/create} (Code: 100, Version: 1.2.15)
2014-04-26 21:51:29.268 Sulphur Public Schools[5338:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Operation is invalid after previous operation.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000103445495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001031a499e objc_exception_throw + 43
    2   Sulphur Public Schools              0x00000001000772b9 -[PFRemoveOperation applyToValue:forKey:ofObject:] + 0
    3   Sulphur Public Schools              0x00000001000537d8 -[PFObject(Private) performOperation:forKey:] + 198
4   Sulphur Public Schools              0x0000000100015eb8 -[NotiOptionsTableViewController genb:] + 520
5   UIKit                               0x0000000101d52f06 -[UIApplication sendAction:to:from:forEvent:] + 80
6   UIKit                               0x0000000101d52eb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
7   UIKit                               0x0000000101e2f880 -[UIControl _sendActionsForEvents:withEvent:] + 203
8   UIKit                               0x0000000101e2edc0 -[UIControl touchesEnded:withEvent:] + 530
9   UIKit                               0x00000001020766f7 _UIGestureRecognizerUpdate + 5149
10  UIKit                               0x0000000101d89a15 -[UIWindow _sendGesturesForEvent:] + 928
11  UIKit                               0x0000000101d8a6d4 -[UIWindow sendEvent:] + 909
12  UIKit                               0x0000000101d6229a -[UIApplication sendEvent:] + 211
13  UIKit                               0x0000000101d4faed _UIApplicationHandleEventQueue + 9579
14  CoreFoundation                      0x00000001033d4d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15  CoreFoundation                      0x00000001033d45f2 __CFRunLoopDoSources0 + 242
16  CoreFoundation                      0x00000001033f046f __CFRunLoopRun + 767
17  CoreFoundation                      0x00000001033efd83 CFRunLoopRunSpecific + 467
18  GraphicsServices                    0x00000001045a2f04 GSEventRunModal + 161
19  UIKit                               0x0000000101d51e33 UIApplicationMain + 1010
20  Sulphur Public Schools              0x000000010002ba03 main + 115
21  libdyld.dylib                       0x00000001039ca5fd start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我认为问题与 removeOjectLine 有关,因为当我尝试按下现在取消订阅按钮时我的应用程序崩溃了。非常感谢任何帮助!

最佳答案

根据 Parse 人员的说法,此错误:'NSInternalInconsistencyException', reason: 'Operation is invalid after previous operation.'是执行两个原子操作而中间没有保存的结果。 addUniqueObject:forKey:removeObject:forKey ,例如,都是原子操作。

所以它可能很简单,例如您在其他方法中运行了一个原子操作而没有适本地保存;但是,根据个人经验,我也注意到,Parse 有时会莫名其妙地无法保存原子操作的结果,因此,在执行新的原子操作后保存时,应用程序随机崩溃并出现此错误。

为了避免这个'NSInternalInconsistencyException' ,我个人尽量避免使用Parse的数组操作。例如,我没有删除一个对象,而是将所有当前对象存储在一个数组中,从该数组中删除该对象,然后将整个修改后的数组发回数据库。是的,它既低效又烦人,但这是我发现的防止此错误的唯一方法。

在查看 Parse 留言板时,似乎很多人都知道这个 'NSInternalInconsistencyException', reason: 'Operation is invalid after previous operation.'更改 PFInstallation 时正如您在问题中所做的那样...例如:PFInstallations gets into an invalid state with "Operation is invalid after previous operation" .希望 Parse 能尽快解决这个问题。

关于ios - 解析取消订阅 channel iOS 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23318900/

相关文章:

javascript - Series 中的 Promise 没有按顺序执行

swift - XCode6 beta 6 Swift 编译器错误

android - 无法理解此堆栈跟踪(parse.com)

ios - 当行数设置为 0 时 UITextView 内容消失

ios - 使用 AFHTTPRequestOperation Manager 时响应失败

javascript - 如何在解析时将objectId保存到其他类?

android - 解析 : make query finsih task before moving to the next task

ios - 无法在 iOS 14 内联 DatePicker 中点击天数

ios - Swift 3 中的索引超出范围

ios - 删除部分时 UICollectionView 崩溃