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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?