iOS:开始在后台处理推送通知?

标签 ios ipad background push-notification

处理接收方应用程序尚未运行时到达的推送通知的正常方法是什么?当应用程序启动时,我的印象是,我可以检测到它是因为推送通知到达而启动的,然后在后台开始下载,而无需启动 GUI。但是,如果用户在下载发生时启动应用程序,人们通常会怎么做?只是显示警告或什么?谢谢。

最佳答案

I am under the impression that I could start the app



这是一个糟糕的词选择。你什么也做不了。用户可能会在收到推送通知后决定打开您的应用程序。

detect that it was started because a Push notification arrived



是的。应用程序委托(delegate)中的 application:didFinishLaunchingWithOptions 将传入包含推送通知数据的字典(在这种情况下,示例代码是本地通知):
if ([UILocalNotification class]) // check if we support local notifications
    {
        UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];

        if (notification) {
            NSString *resourcePath = [notification.userInfo objectForKey:@"resourcePath"]; // get arbitrary data that you stored in the notification (key-value pairs)
        }

        application.applicationIconBadgeNumber = 0; // reset the app icon badge number
    }

in the background without ever starting the GUI



你不能那样做。应用程序启动的唯一可能工作流程是通知->用户点击阅读更多按钮->应用程序在前台打开。

what do people normally do if the user starts an app when that downloading is happening? Just display a warning or something?



这个问题并不真正适用,因为应用程序无法在后台启动,但一般来说,如果您的应用程序在幕后做某事,用户不应该关心发生了什么。因此,除非应用程序需要数据才能运行,否则不应有任何形式的警告。

关于iOS:开始在后台处理推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8468793/

相关文章:

android - 从网站获取信息到移动应用程序

iphone - 在 iOS 上实现 "user to user"VoIP 的最佳方式

jquery - 背景图像上方的背景颜色

ios - 在 iOS7 UITabbarController 中,如何停止在点击已选择的 tabBarItem 时将 navigationController 重置为 root?

在后台运行的 Linux 守护进程

php - 需要从浏览器运行一个长的 php 脚本

ios - NSFetchedResultsController 一致延迟更新 UITableView 单元格;插入立即起作用

iOS + Tesseract Ocr + OpenCV

ios - 如何选择接收到触摸事件的 UIView

iphone - 当我打开 iPhone 3G 时,应用程序第二次在闪屏中崩溃