简体   繁体   English

如何在我的应用未运行时处理推送通知

[英]how can I handle push notification when my app is not running

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

A short example: 一个简短的例子:

- (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(@" - ");
    } 

Edited: About the NSDictionary you received, from Apple's official documentation: 编辑:关于您收到的NSDictionary,来自Apple的官方文档:

You can access the contents of the aps dictionary—though you shouldn't need to in most cases—using the following keys: 您可以访问aps词典的内容 - 尽管在大多数情况下您不需要使用以下键:

  1. alert—The value may either be a string for the alert message or a dictionary with two keys: body and show-view. alert-该值可以是警报消息的字符串,也可以是包含两个键的字典:body和show-view。 The value of the former is the alert message and the latter is a Boolean (false or true). 前者的值是警报消息,后者是布尔值(false或true)。 If false, the alert's View button is not shown. 如果为false,则不显示警报的“查看”按钮。 The default is to show the View button which, if the user taps it, launches the application. 默认设置是显示“查看”按钮,如果用户点击该按钮,则启动该应用程序。
  2. badge—A number indicating the quantity of data items to download from the provider. badge - 一个数字,指示从提供程序下载的数据项的数量。 This number is to be displayed on the application icon. 此编号将显示在应用程序图标上。 The absence of a badge property indicates that any number currently badging the icon should be removed. 缺少徽章属性表示应删除当前标记图标的任何数字。
  3. sound—The name of a sound file in the application bundle to play as an alert sound. sound-应用程序包中声音文件的名称,用作警报声音。 If “default” is specified, the default sound should be played. 如果指定“default”,则应播放默认声音。

The dictionary may also have custom data defined by the provider according to the JSON schema. 字典还可以具有由提供者根据JSON模式定义的自定义数据。 The properties for custom data should be specified at the same level as the aps dictionary. 应该在与aps字典相同的级别指定自定义数据的属性。 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. 但是,自定义属性不应用于海量数据传输,因为每个通知(256字节)存在严格的大小限制,并且无法保证传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到推送通知后,如何判断我的iPhone应用程序是否正在运行? - How do I tell if my iPhone app is running when a Push Notification is received? 如何在我的应用中获取推送通知设置? - How can i fetch Push Notification settings in my app? 当应用程序处于后台或运行状态时,处理推送通知,而不是在应用程序终止时 - Handle push notification when app is in Background or Running state not when app is terminated 当我收到推送通知时如何播放声音(应用正在运行时) - How to play sound when i received push notification(when app is running) 在应用未运行时推送通知数据? - Push notification data when app is not running? 如果我从App Store删除应用程序,可以向我的应用程序发送推送通知 - Can I send Push Notification to my app if I delete my app from App Store 从推送通知打开应用程序时,如何进入某个视图? - How can I go to a certain view when the app is opened from push notification? 如何处理Push on App未运行状态? - How to handle Push on App not running state? 删除应用程序时推送通知 - Push Notification when I delete the app 即使应用未运行(即使不是在后台),我的设备上是否也收到推送通知? - Are push notification received on my device even if the app is not running (not even in background) ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM