user1120133
user1120133

Reputation: 3234

App crashes after updating to iOS sdk 8.0

Updated to iOS sdk 8.0.

App crashes with the error

[PFInternalUtils assertValidClassForQuery:] at PFInternalUtils.m:372

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: (null)'
*** First throw call stack:
(
  0   CoreFoundation                      0x032d6df6 __exceptionPreprocess + 182
1   libobjc.A.dylib                     0x02f60a97 objc_exception_throw + 44
2   CoreFoundation                      0x032d6d1d +[NSException raise:format:] + 141
3                                0x000e60b2 +[PFInternalUtils assertValidClassForQuery:] + 324
4                                 0x000ce3cb -[PFQuery whereKey:equalTo:] + 91
5                                 0x000b7391 -[InboxViewController retrieveMessages] + 193
6                                 0x000b624c -[InboxViewController viewWillAppear:] + 236
7   UIKit                               0x01aa614f -[UIViewController _setViewAppearState:isAnimating:] + 545
8   UIKit                               0x01aa66ca -[UIViewController __viewWillAppear:] + 148
9   UIKit                               0x01ad8389 -[UINavigationController _startTransition:fromViewController:toViewController:] + 931
10  UIKit                               0x01ad8fdb -[UINavigationController _startDeferredTransitionIfNeeded:] + 669
11  UIKit                               0x01ad9c52 -[UINavigationController __viewWillLayoutSubviews] + 57
12  UIKit                               0x01c4bebc -[UILayoutContainerView layoutSubviews] + 213
13  UIKit                               0x019d59c0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608
14  libobjc.A.dylib                     0x02f76771 -[NSObject performSelector:withObject:] + 70
15  QuartzCore                          0x00c9827f -[CALayer layoutSublayers] + 152
16  QuartzCore                          0x00c8c105 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 397
17  QuartzCore                          0x00c8bf60 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
18  QuartzCore                          0x00bea676 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
19  QuartzCore                          0x00beba3c _ZN2CA11Transaction6commitEv + 392
20  QuartzCore                          0x00cb1789 +[CATransaction flush] + 52
21  UIKit                               0x019487e6 -[UIApplication _reportMainSceneUpdateFinished:] + 39
22  UIKit                               0x01949761 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3163
23  UIKit                               0x01961d30 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
24  UIKit                               0x01947d7f -[UIApplication workspaceDidEndTransaction:] + 155
25  FrontBoardServices                  0x064069de __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
26  FrontBoardServices                  0x0640646f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
27  FrontBoardServices                  0x06418425 __31-[FBSSerialQueue performAsync:]_block_invoke + 26
28  CoreFoundation                      0x031fa7a0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
29  CoreFoundation                      0x031f00b3 __CFRunLoopDoBlocks + 195
30  CoreFoundation                      0x031eff0b __CFRunLoopRun + 2715
31  CoreFoundation                      0x031ef1ab CFRunLoopRunSpecific + 443
32  CoreFoundation                      0x031eefdb CFRunLoopRunInMode + 123
33  UIKit                               0x01947744 -[UIApplication _run] + 571
34  UIKit                               0x0194ae16 UIApplicationMain + 1526
35                                0x000b567d main + 141
36  libdyld.dylib                       0x04dddac9 start + 1
37  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

EDIT:

- (void)retrieveMessages {
PFQuery *query = [PFQuery queryWithClassName:@"Messages"];
[query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (error) {
        NSLog (@"Error:%@ %@", error, [error userInfo]);

    }
    else {
        //we found messages
        self.messages = objects;
        [self.tableView reloadData];
        NSLog (@"Retrieved %d messages", [self.messages count]);

    }

    if([self.refreshControl isRefreshing]) {
        [self.refreshControl endRefreshing];
    }
}];
 }



 - (void)viewDidLoad
{
[super viewDidLoad];

self.moviePlayer = [[MPMoviePlayerController alloc] init];

PFUser *currentUser = [PFUser currentUser];
if (currentUser){
    NSLog (@"CurrentUser:%@", currentUser.username);
}
else{

[self performSegueWithIdentifier:@"showLogin" sender:self];

}

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(retrieveMessages) forControlEvents:UIControlEventValueChanged];
   }


 - (void) viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

[self.navigationController.navigationBar setHidden:NO];

[self retrieveMessages];

}

Using parse.com as backened.

before update it was working fine.

Any idea please how to fix this error.

Thanks for help.

Upvotes: 0

Views: 1322

Answers (1)

AStopher
AStopher

Reputation: 4540

This error seems to be occurring because you are executing a function where a user must be logged in, but isn't when the function is executed. Looking at other questions, the specific error seems to be related to 4 0x000ce3cb -[PFQuery whereKey:equalTo:] + 91. Looking at the linked question above, the full problem statement may well be [PFQuery whereKey:equalTo:[PFUser currentUser]].

Looking at your code the following is the code that's the root of the problem:

[query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];

As said before, you'll need to catch if a user isn't logged in and prevent the main code in the function from running by adding a return.

One of the answers from the linked question:

I just ran into this and it was due to the fact that I was doing an equalTo:[PFUser currentUser] in a PFQuery but there was no logged-in user at that point.

As to why this started occurring when you upgraded to the iOS 8 SDK (you're using Xcode 6.0.1 & the latest Parse SDK, right?), I'm not sure; perhaps it has nothing to do with the upgrade and you changed something to make this error occur.

Upvotes: 2

Related Questions