Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone local notification in simulator

I just downloaded xcode and trying to make local notification example. The question is if local notification works in simulator?

thank you

like image 532
user349302 Avatar asked Aug 28 '10 00:08

user349302


People also ask

Can iOS simulator receive local notifications?

“Simulator supports simulating remote push notifications, including background content fetch notifications. In Simulator, drag and drop an APNs file onto the target simulator. The file must be a JSON file with a valid Apple Push Notification Service payload, including the “aps” key.

Do notifications work on iOS simulator?

As of Xcode 11.4, users are finally able to test Push Notifications via the iOS Simulator. We can send push notifications to the simulator in two different ways: Use a command provided by Xcode Command Line Tools in Terminal. Drag and drop an APNs file onto the target simulator.

Can I get notification on simulator?

If your target platform is Android, you can test a push notification on an emulator if the emulator target uses a version of Google APIs to receive the push notifications.

Can we send push notification to iOS simulator?

Yes, that's true. I always wondered if I can send a Push Notification on iOS simulator instead getting a real device while developing applications. Simulator supports simulating remote push notifications, including background content fetch notifications.


1 Answers

Yes, local notifications work with the simulator. However, make sure you are implementing application:didreceiveLocalNotification in your app delegate if you want to see the notification while your app is in the foreground:

- (void)application:(UIApplication *)application     didReceiveLocalNotification:(UILocalNotification *)notification {     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"MyAlertView"         message:notification.alertBody         delegate:self cancelButtonTitle:@"OK"         otherButtonTitles:nil];     [alertView show];     if (alertView) {         [alertView release];     } } 

Otherwise, make sure you schedule your notification for some time in the future, then close the application, in order to see the Apple sample work:

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) return; NSDate *fireTime = [[NSDate date] addTimeInterval:10]; // adds 10 secs localNotif.fireDate = fireTime; localNotif.alertBody = @"Alert!"; [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; [localNotif release]; 

It's easy to think you're not implementing the test code correctly, and you just aren't handling the event while the app is running.

like image 95
bojolais Avatar answered Sep 22 '22 11:09

bojolais