I just downloaded xcode and trying to make local notification example. The question is if local notification works in simulator?
thank you
“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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With