当我的应用程序未运行时如何处理推送通知 [英] how can I handle push notification when my app is not running

查看:48
本文介绍了当我的应用程序未运行时如何处理推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序未运行时如何处理推送通知我正在为 ios3 开发.请帮忙

how can I handle push notification when my app is not running i am developing for ios3 .please help

推荐答案

一个简短的例子:

- (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,来自 Apple 的官方文档:

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. alert—该值可以是警报消息的字符串或有两个键的字典:body 和显示视图.前者的值为警报消息,后者是布尔值(假或真).如果为假,则警报的查看按钮未显示.这默认是显示查看按钮如果用户点击它,则启动应用程序.
  2. badge——指示要下载的数据项数量的数字来自供应商.这个数字是显示在应用程序图标上.缺少徽章属性表示当前任何数字标记图标应该被删除.
  3. sound - 应用程序包中要播放的声音文件的名称警报声.如果默认"是指定,默认声音应该是

字典也可能有提供者定义的自定义数据根据 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.

这篇关于当我的应用程序未运行时如何处理推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆