热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在ios10中处理后台推送通知?

如何解决《如何在ios10中处理后台推送通知?》经验,为你挑选了1个好方法。

我不是在后台处理推送通知.

对于以下步骤中的处理推送通知: -

    在功能 - >启用远程通知.

    在功能 - >后台模式 - >启用远程通知.

    在didFinishLaunchingWithOptions中给出了ios 10的所有权限.

    用于推送通知UNUserNotificationCenter.

    App In Foreground然后推送通知工作正常并且在方法调用之下:

    userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
    

但我的问题是app在后台然后没有调用任何方法.所以任何人有想法或解决方案的背景为ios 10处理推送通知然后请帮助我.

谢谢.



1> Abhishek Tha..:

当app在前台时调用willPresentNotification.看看他们的文档

 - (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    // The method will be called on the delegate only if the application is in the foreground.
    // If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented.
    // The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list.
    // This decision should be based on whether the information in the notification is otherwise visible to the user.

}

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void(^)())completionHandler {
    // The method will be called on the delegate when the user responded to the notification by opening the application,
    // dismissing the notification or choosing a UNNotificationAction.
    // The delegate must be set before the application returns from applicationDidFinishLaunching:.

}

尝试办理登机手续即可didReceiveNotificationResponse获得所需资料.

另外如果需要获取任何数据或任何处理,请在后台模式下启用后台获取并使用以下方法

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{

    completionHandler(UIBackgroundFetchResultNewData);
}

根据应用程序状态处理APNS

   if(application.applicatiOnState== UIApplicationStateInactive)
     {
        /* 
        # App is transitioning from background to foreground (user taps notification), do what you need when user taps here!
         */    
    }
    else if(application.applicatiOnState== UIApplicationStateActive)
    {
        /*
         # App is currently active, can update badges count here
       */
    }
    else if(application.applicatiOnState== UIApplicationStateBackground)
    {
        /* # App is in background, if content-available key of your notification is set to 1, poll to your backend to retrieve data and update your interface here */
    }


推荐阅读
author-avatar
good7758
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有