Discussion Forums  >  Xcode, Errors, Installing, Configuring

Replies: 19    Views: 493

sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
05/16/13 03:03 PM (12 years ago)

Terminating app due to uncaught exception

I am trying to set up push notifications using parse.com and now when I run my project it works fine on the simulator but not on my iPhone device. I'm getting the following error: 2013-05-16 14:56:58.276 dominicscypress[2576:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'You have to call setApplicationId:clientKey: on Parse to configure Parse.' *** First throw call stack: (0x32a2f2a3 0x3a68997f 0x32a2f1c5 0x1991ab 0x196809 0x1798a3 0x1ac9f3 0x7b645 0x34a8a39f 0x34a8ae29 0x354a0305 0x32a04173 0x32a04117 0x32a02f99 0x32975ebd 0x32975d49 0x364f22eb 0x3488b301 0xc25d9 0x3aac0b20) libc++abi.dylib: terminate called throwing an exception (lldb) Can anyone please help fix this? --sxywebgirl
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/16/13 03:09 PM (12 years ago)
'You have to call setApplicationId:clientKey: on Parse to configure Parse.' Just taking a stab, but it looks like Parse wants some kind of API key. Have you registered and obtained one? 'Where' did you put the code that provides the API key? I've found with Google Maps, Scringo, and a few others that the API Key needs to go in the appDelegate.m file, rather than in the plugin.m file. Just a thought. Cheers! -- Smug
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 03:16 PM (12 years ago)
ok, if I remove this part of the code that I needed to add for push notification it will run successfully on my device. //didRegisterForRemoteNotificationsWithDeviceToken... - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { Store the deviceToken in the current installation and save it to Parse. PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:newDeviceToken]; [currentInstallation saveInBackground];
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 03:17 PM (12 years ago)
@SmugWimp That was my first thought but I have a appKey and clientKey in the code already.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/16/13 03:24 PM (12 years ago)
"Where" do you place that code? Is there anything in the parse documentation on where it should go? I only ask because one SDK I used would not work unless the api key was called very early in the application, so I had to put it in my AppDelegate files, rather than in my plugin file, which was where I used the features. Cheers! -- Smug
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 03:27 PM (12 years ago)
This is all the code I'm adding... 5. Adding Code for a Push Enabled iOS Application We are now ready to start programming. We need to make a few modification to the app delegate in order to receive push notifications. To register the current device for push, call the method [application registerForRemoteNotificationTypes:] in the app delegate's [application:didFinishLaunchingWithOptions:] method. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // Register for push notifications [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; ... } If the registration is successful, the callback method [application:didRegisterForRemoteNotificationsWithDeviceToken:] in the application delegate will be executed. We will need to implement this method and use it to inform Parse about this new device. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { // Store the deviceToken in the current installation and save it to Parse. PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:newDeviceToken]; [currentInstallation saveInBackground]; } When a push notification is received while the application is not in the foreground, it is displayed in the iOS Notification Center. However, if the notification is received while the app is active, it is up to the app to handle it. To do so, we can implement the [application:didReceiveRemoteNotification] method in the app delegate. In our case, we will simply ask Parse to handle it for us. Parse will create a modal alert and display the push notification's content. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; }
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/16/13 03:46 PM (12 years ago)
Ok, and it looks as if they're requesting that you put it into your appDelegate file, so that would be your <appname>_appDelegate.m file, located in your 'BT_Config' directory within your project. The first part: ... // Register for push notifications [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; ... would go somewhere in your "didFinishLaunchingWithOptions" method. I'd suggest somewhere around line 122 after the loadAppData call. Then the other two methods: - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { // Store the deviceToken in the current installation and save it to Parse. PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:newDeviceToken]; [currentInstallation saveInBackground]; } and - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [PFPush handlePush:userInfo]; } should 'probably' go within the app delegate file, but not 'within' any other methods. So between the brackets of any two methods should work. A 'possible' suggested location would be towards the bottom of the file, around line 1257 "after" the dealloc method, but before the "@end" which is the end of the file. But again, as long as it isn't 'inside' any other method, you should be good. Maybe this might work? Cheers! -- Smug
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 05:04 PM (12 years ago)
Did your suggestion... I got a Duplicate declaration of method error "application:didRegisterForRemoteNotificationsWithDeviceToken" and "applicationdidReceiveRemoteNotification" so I commented out the same original BT methods...and it runs and starts to open on device but then crashes and I get a black screen. I've been at this since 8am moving the code to diff places trying everything I can think of and still I cant get it to work!!! I need food and to stretch, sitting at the computer all day with only a latte for sustenance is a bad habit. I appreciate your idea and if you have any others I'll be more than happy to try them :) Thanks!
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/16/13 05:44 PM (12 years ago)
Don't 'duplicate' the methods; you only need one in your module. What you're doing is 'integrating' their code into your existing method. For example, don't paste this entire section: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... // Register for push notifications [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; ... } You only need the code within the ellipses (...) cut and pasted into your 'didfinishlaunchingwithoptions' method... Starting with '// Register for push notifications ' and ending with 'UIRemoteNotificationTypeSound];' For each method that claims to have a duplicate, 'find' the method, and integrate (add) the code in with the method, rather than pasting a new one. Be sure to use comments (//) so that you can differentiate 'your' code from the original BT code. Cheers! -- Smug
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 06:16 PM (12 years ago)
@Smug I must be tired, usually if I stay on something I get it, this is what I'm doing and it still doesn't work :-( //didRegisterForRemoteNotificationsWithDeviceToken... -(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{ PFInstallation *currentInstallation = [PFInstallation currentInstallation]; [currentInstallation setDeviceTokenFromData:deviceToken]; [currentInstallation saveInBackground]; /* [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"didRegisterForRemoteNotificationsWithDeviceToken: Device Token: %@", deviceToken]]; //if we have a token, and a register it... if([deviceToken length] > 1 && [[self.rootApp registerForPushURL] length] > 1){ //clean up token... NSString *useToken = [NSString stringWithFormat:@"%@", deviceToken]; useToken = [useToken stringByReplacingOccurrencesOfString:@"<"withString:@""]; useToken = [useToken stringByReplacingOccurrencesOfString:@">"withString:@""]; useToken = [useToken stringByReplacingOccurrencesOfString:@" "withString:@""]; //save it for next time... [BT_strings setPrefString:@"lastDeviceToken" valueOfPref:useToken]; //append deviceToken and deviceType to end of URL... NSString *useURL = [[self.rootApp registerForPushURL] stringByAppendingString:[NSString stringWithFormat:@"&deviceType=%@", @"ios"]]; useURL = [useURL stringByAppendingString:[NSString stringWithFormat:@"&deviceToken=%@", useToken]]; //append currentMode ("Live" or "Design") to end of URL... useURL = [useURL stringByAppendingString:[NSString stringWithFormat:@"&currentMode=%@", [self currentMode]]]; //merge environment variables in URL... useURL = [BT_strings mergeBTVariablesInString:useURL]; //escape the URL... NSString *escapedUrl = [useURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //tell the BT_device to register on the server (the device class makes the URL request)... [BT_device registerForPushNotifications:escapedUrl]; } */ } //didReceiveRemoteNotification.. -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ [PFPush handlePush:userInfo]; /* [BT_debugger showIt:self theMessage:[NSString stringWithFormat:@"didReceiveRemoteNotification %@", @""]]; //don't do anything if the app is not in the foreground. iOS handles inbound APNS message when app is in the background... if(application.applicationState == UIApplicationStateActive){ NSString *alertMsg; NSString *badge; NSString *sound; //alert message... if([[userInfo objectForKey:@"aps"] objectForKey:@"alert"] != NULL){ alertMsg = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"]; } //badge... if([[userInfo objectForKey:@"aps"] objectForKey:@"badge"] != NULL){ badge = [[userInfo objectForKey:@"aps"] objectForKey:@"badge"]; } //sound... if([[userInfo objectForKey:@"aps"] objectForKey:@"sound"] != NULL){ sound = [[userInfo objectForKey:@"aps"] objectForKey:@"sound"]; } //if we have a sound... if([sound length] > 1){ [self performSelector:@selector(playSoundFromPushMessage:) withObject:sound afterDelay:.1]; } //show messsage... UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:alertMsg delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", "OK") otherButtonTitles:nil]; [alert show]; [alert release]; } */ }
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 06:21 PM (12 years ago)
I did notice that there is a slight difference in the methods called for application didRegisterForRemoteNotificationsWithDeviceToken... Original: -(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{ New: - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken { I've tried to match them by changing them both ways but still doesn't work
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/16/13 06:31 PM (12 years ago)
Well, you should not be 'removing' anything from the methods that are there... You should only be 'augmenting' the existing methods with the additional code. So, methods that are already there, leave them there, and 'add' code. Methods that are not there, need to be added. Sorry if it sounds confusing. Cheers! -- Smug
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 06:45 PM (12 years ago)
If I just "add" the additional code I get an error like this.... https://dl.dropboxusercontent.com/u/59740936/pushCodeError.jpg
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 06:50 PM (12 years ago)
Smug, I have to say thank you for being so helpful! This is all new to me and I feel like I just keep hitting my head on a wall and then I move forward a bit and then hit my head on the wall with another challenge. I'm so close to being done and submitting my app to iTunes! It's driving me crazy that I cant figure this out. Thanks again for your help!
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 07:16 PM (12 years ago)
If I accept the change that is suggested in the code error I get this... https://dl.dropboxusercontent.com/u/59740936/pushCodeError2.jpg
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 08:03 PM (12 years ago)
Dang! I think I got it!!! It's all in where you put the code..... //didFinishLaunchingWithOptions... -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ //Parse IDs [Parse setApplicationId:@"WyNDAMidf*****************" clientKey:@"5GoA7KyoeTxnN7*************"]; // Register for push notifications [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound]; [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
 
BuzzingSteve
Aspiring developer
Profile
Posts: 526
Reg: Jun 24, 2011
Vancouver, Cana...
11,660
like
05/16/13 08:09 PM (12 years ago)
@sxywebgirl....Glad you got it working...You might want to edit your last post and remove your ApplicationID and clientKey from the code you posted...just saying :-)
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 08:11 PM (12 years ago)
Ok, got it working, but now I have two push notifications showing up. I close one and the same one shows again....... At least no errors!!! LOL
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 08:13 PM (12 years ago)
Thanks for the reminder @ BuzzingSteve! I was so focused on making this work!!
 
sxywebgirl
Aspiring developer
Profile
Posts: 158
Reg: Apr 12, 2013
Altadena, CA
7,530
like
05/16/13 08:44 PM (12 years ago)
Still have a semantic issue but it seems to be working... Not sure what to do to get rid of that. Will look at it in the morning. So done for the day, need a glass of wine, lol. --sxywebgirl
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.