starwar2012 2013-07-02 05:54 采纳率: 0%
浏览 1012

如何检索和处理远程推送通知?

在应用没在运行时获取远程通知,我找到的方法:

UILocalNotification *localNotification  = [launchOptions 
                   objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]

在方法:

 - (BOOL)application:(UIApplication *)application 
               didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

并没有得到信息。

后来我采用alertView显示信息,也没显示。

为什么?请高手帮忙解决

  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-01 13:00
    关注

    如果你的应用没有在运行,那么你应该在 application:didFinishLaunchingWithOptions: 方法中检查远程通知的参数。你可以通过以下代码来获取远程通知的内容:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (remoteNotification) {
            // 远程通知被收到了
            // 在这里处理通知内容
        }
    
        return YES;
    }
    

    如果你使用的是 UIAlertView 来显示通知信息,请注意 UIAlertView 已经被废弃,建议使用 UIAlertController 代替。

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献