且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我该怎么处理推送通知时,我的应用程序不运行

更新时间:2022-11-20 23:38:25

一个简单的例子:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    NSDictionary *tmpDic = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];

    //if tmpDic is not nil, then your app is launched due to an APNs push, therefore check this NSDictionary for further information
    if (tmpDic != nil) {
        NSLog(@" - launch options dict has something ");
        NSLog(@" - badge number is %@ ", [[tmpDic objectForKey:@"aps"] objectForKey:@"badge"]);
        NSLog(@" - ");
    } 

编辑:关于你的NSDictionary收到来自苹果的官方文档:

Edited: About the NSDictionary you received, from Apple's official documentation:

您可以访问的APS的内容
  字典虽然你不应该需要
  在大多数情况下,使用下面的
  键:

You can access the contents of the aps dictionary—though you shouldn’t need to in most cases—using the following keys:


      
  1. 警报的值可以是对警报消息或一个字符串
      字典,两个键:身体和
      显示视图。前者的值是
      警报消息,后者是一个
      布尔(或真或假)。如果为false,
      警报的视图按钮不会显示。该
      默认是显示视图按钮
      其中,如果用户点击它,汽艇
      应用程序。

  2.   
  3. 徽章-A指示的数据项的数量数下载
      从供应商。这个数字是为了
      上的应用程序图标被显示。
      由于没有一个徽章属性的
      表示任何数目目前
      徽章的图标应该被删除。

  4.   
  5. 声音的应用程序包中的声音文件的名称为玩
      警报声。如果默认为
      指定,则默认的声音应
      播放。

  6.   

该词典还可以有
  由供应商定义的自定义数据
  根据JSON模式。该
  自定义数据属性应该是
  在相同的水平的APS指定
  字典。然而,自定义的
  属性不应该被用于大规模
  数据传输,因为有一个
  每个通知严格的大小限制
  (256字节)和递送是不
  保证的。

The dictionary may also have custom data defined by the provider according to the JSON schema. The properties for custom data should be specified at the same level as the aps dictionary. However, custom-defined properties should not be used for mass data transport because there is a strict size limit per notification (256 bytes) and delivery is not guaranteed.