Push Notifications in Mavericks iOS Simulator

ぃ、小莉子 提交于 2019-11-27 03:50:43

No, there is still no API to support push notifications in the simulator. You’ll have to use a device.

Kevin Sylvestre

iOS 8 and Xcode 6 did indeed add some additional integration to push notifications. If you select the iPhone 6 or iPhone 6 Plus simulator your app will now appear under Settings with a full featured notifications settings screen (see attached) and will show the in app modal when requesting push notification permissions for the first time. This is only true for the iPhone 6 and iPhone 6 Plus simulators.

However, in iOS 8 you will still get message in console as 'remote notifications are not supported in the simulator' and hence you have to use device only.

Even though iPhone 6 and iPhone 6+ simulators have setting for push notifications and even show you the push notification prompt, an attempt to register for push notifications from simulator still fails with Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x7fc786b4af90 {NSLocalizedDescription=remote notifications are not supported in the simulator}. So, your best bet is still to use a device.

If you want to simulate push notifications in the iOS simulator, you can use this library: https://github.com/acoomans/SimulatorRemoteNotifications

Update XCode8 GM Release

Log: Push notifications now fail with the old haunting poem:

remote. 
notifications are not.
supported in the simulator.

I now question myself and my sanity. This feature that I'd long hoped for, and for a brief moment had in my hand, or so I thought. Was it all just a dream? Are any of us really here?

<fade out...>

Original Post

As of the iOS10 beta (XCode Version 8.0 beta (8S128d)), simulators seem to be getting Push notifications. Note that although prior to iOS10, devices could receive local notifications, they did not receive push notifications.

I don't have any official source on this, just anecdotally, features that rely on push notifications which used to fail, are now succeeding on iPhone 5, 5s, 6, 6+ simulators.

I also verified that we're hitting the registration block in AppDelegate.

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  NSLog(@"Successfully registered!");
  doSomething(notificationSettings);
}

Looking forward to using remote notifications in the simulator when iOS 10 comes out.

In the meantime I use the Xcode command line to test notification behavior:

p [((CustomAppDelegateClass *)((UIApplication *)[UIApplication sharedApplication]).delegate) application:[UIApplication sharedApplication] didReceiveRemoteNotification:@{@"aps": @{@"alert": @"Alert Message"}, @"info": @{@"object": @"value"}}];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!