iOS Push Notifications with empty aps dictionary

梦想与她 提交于 2019-12-05 01:17:57

If there is no badge, no alert, and no sound specified in the dictionary (for the "aps" key) then a default message will not appear and it will be completely silent.

Look again at example 5 in the document you referenced. aps can be empty, and you can specify whatever custom data you would like as they do with the "acme2" key. The "acme2" data is an example of where your server's "special" payload could reside within the JSON payload.

You don't need to tell the server that your app is running. The server can send the special payloads through APNS regardless if your app is running or not, and you will receive that special payload in one of two ways (assuming of course that the push does reach the device... which is not guaranteed):

  1. If your application is in the foreground then iOS will not intercept the notification. You will receive the notification in your app delegate's application:didReceiveRemoteNotification: method (provided that your app delegate does override the method).
  2. If iOS did intercept your push, then when you choose to launch your application in response to the notification then you will need to retrieve the "push dictionary" in your app delegate's application:didFinishLaunchingWithOptions: method as in the following example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self application:application didReceiveRemoteNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!