OGeek|极客世界-中国程序员成长平台

标题: ios - 关闭应用程序时如何从推送通知中获取数据? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:44
标题: ios - 关闭应用程序时如何从推送通知中获取数据?

我想在应用关闭时从推送通知中获取数据。我正在使用下面给出的以下代码:

- (void) applicationUIApplication *)application didReceiveRemoteNotificationNSDictionary *)userInfo fetchCompletionHandlervoid (^)(UIBackgroundFetchResult))completionHandler 
{
    NSDictionary *aps = userInfo[@”aps”];

    if (state == UIApplicationStateInactive){
    // user tapped notification
         NSLog(@"results%@",aps);
         completionHandler(UIBackgroundFetchResultNewData);
    } else {
    // app is active             
         completionHandler(UIBackgroundFetchResultNoData);
    }
}

在上面的代码中 NSLog(@"results%@",aps);应用程序在后台时不会打印值。请帮帮我



Best Answer-推荐答案


didReceiveRemoteNotification 仅在您点击通知时有效。所以它只会在您点击通知时为您提供数据,并且您的应用会打开。

如果要获取 NSDictionary *aps = userInfo[@”aps”];当您的应用程序处于终止状态时,您必须实现 pushkit 框架。

您可以从 1 my answer 下载示例代码

Can someone share a sample code of iOS Xamarin PushKit in C#?

Register for voip notifications outside of app delegate

来源 https://github.com/hasyapanchasara/PushKit_SilentPushNotification

关于ios - 关闭应用程序时如何从推送通知中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38429156/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4