How to test UILocalNotification in didFinishLaunchingWithOptions file

I would like to check how the application works when the application closes and the user deletes the notification in the notification center so that my application is launched. In - didFinishLaunchingWithOptions you can check the key UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; but how can I debug it?

If I run the application in Xcode, I left the application that will lose connection with Xcode.

+7
source share
4 answers

If you set your Xcode scheme to run manually (Edit Scheme> Run> Info), you can stop your application from starting after you scheduled UILocalNotification .

Then, if you run the application again, it will not start until you launch it from the simulator / device.

Then you can wait until the notification appears, and click on the notification, which then launches your application (manually!). This way you can debug UILocalNotification from launchOptions application:didFinishLaunchingWithOptions:

Just remember that for debugging, you probably want to schedule UILocalNotification for a date of about 10 seconds or so in the future, it always hurts to debug time-related things.

Good luck.

+12
source

The didFinishLaunchingWithOptions: method will not be called until the application starts. But closing the application does NOT make your application lose contact with xcode, since your application is running in the background.

I might have missed something, but you can really run your application on your device and then continue as you wish.

You can also try this code in didFinishLaunchingWithOptions: if the log is still not working.

 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"options" message:[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey] description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; return YES; 
0
source

Keep the application in the background, connected to xcode in debug mode, and give one local notification, then go to the notification center and click on this notification, and the didReceiveLocalNotification: function will be called.

The only difference between the local notification that comes when the application is completely closed is that you need to write the code in the didFinishLaunchingWithOptions file (you can copy a stick of the same code that you wrote for the didReceiveLocalNotification: function) and didReceiveLocalNotification: not called.

Hope this information helps you.

0
source

Maybe this is a stupid answer. :)

I usually put UIAlertView . And set the text in alertview depending on the local notification.

Another is to exit the application. Put some NSLog in applicationDidFinishLaunching . Quit the application. Go to Xcode-> Organizer . Then select your device on the Devices tab. Select Console options. You can see the magazines there.

Hope this helps.

0
source

All Articles