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

发布于 2024-12-20 11:30:28 字数 132 浏览 4 评论 0原文

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

what is the normal way to go about dealing with a Push notification that arrives when the recipient app is not already running? I am under the impression when the app starts, I can detect that it was started because a Push notification arrived, and then start downloading in the background without ever starting the GUI. But what do people normally do if the user starts an app when that downloading is happening? Just display a warning or something? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漆黑的白昼 2024-12-27 11:30:28

我的印象是我可以启动该应用

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

检测到它是因为推送通知到达而启动的

是的。应用程序委托中的 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
    }

在后台运行,无需启动 GUI

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

如果用户在下载时启动应用程序,人们通常会做什么?只是显示警告或其他内容?

这个问题并不真正适用,因为应用程序无法在后台启动,但一般来说,如果您的应用程序在后台执行某些操作,用户不应该关心发生了什么。因此,除非应用程序运行需要数据,否则不应出现任何类型的警告。

I am under the impression that I could start the app

That's a poor choice of words. You cannot do anything. The user may decide to open your app after receiving the push notification.

detect that it was started because a Push notification arrived

Yep. application:didFinishLaunchingWithOptions in your app delegate will pass in a dictionary containing push notification data (in this case, the example code is a local notification):

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

You can't do that. The only possible workflow for app launch is notification->user taps read more button->app opens in the foreground.

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

This question doesn't really apply since the app can't be started in the background, but in general users shouldn't care about what's happening if your app is doing something under the covers. Therefore, there should be no warning of any kind unless the data is required for the app to function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文