【问题标题】:Apple Push Notification Service using Urban Airship in iPhone在 iPhone 中使用 Urban Airship 的 Apple 推送通知服务
【发布时间】:2010-08-11 10:04:07
【问题描述】:

我已经使用 Urban Airship 实现了 Apple 推送通知服务,并在我的应用程序中成功收到了通知。如果我收到警报视图的通知,如果我单击警报视图中的视图按钮,它将启动应用程序。通常它发生在 APNS 中。但是我的客户想要,如果 RSS 提要和警报视图中发生任何更新,如果我们单击警报视图中的视图,它应该转到应用程序中的特定提要,而不是启动应用程序。那么有可能做到这一点吗?是否有可能为我的应用程序中的特定警报视图按钮编写事件。

这是我的示例代码,

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

       [[UIApplication sharedApplication] registerForRemoteNotificationTypes:   UIRemoteNotificationTypeBadge                                                           | UIRemoteNotificationTypeSound                                                                          | UIRemoteNotificationTypeAlert];

        [window addSubview:viewcontrollers.view];

        [window makeKeyAndVisible];

        NSLog(@"remote notification2: %@",[launchOptions description]);

      return YES;

     }

在这种方法 didFinishLaunchingWithOptions 中,我无法获取字典值,它总是获取 Null 值。是否有可能在此方法中获取字典值(通知来了)。

     - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

            NSString *message = [userInfo descriptionWithLocale:nil indent: 1];

            NSLog(@"The message string is %@",message);

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Remote Notification" message: message delegate: nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
            [alert show];
            [alert release];
      }

在这种方法中,我可以获得字典值。但此方法仅在应用程序运行时发生任何更新时调用。

请指导我!

谢谢

【问题讨论】:

    标签: iphone apple-push-notifications urbanairship.com


    【解决方案1】:

    确实有可能做到这一点。在您的 application:didReceiveRemoteNotification 方法中,您将获得一个包含所有推送通知数据的 NSDictionary。您要做的是将有效负载中的一些 ID 或 URL 发送到 Urban Airship。比如:

    {
        "aps": {
            "alert": "New RSS entry"
        },
        "entry_id": "XYZ123"
    }
    

    然后您可以编写代码来获取应用程序中正确的提要条目。

    【讨论】:

    • +1,@robotadam,感谢您的回复。请参阅我更新的问题,并请提及我做错了什么。谢谢。
    • 我不确定你现在的问题是什么——你有来自推送通知的数据,是吗?其余的似乎将成为您其余代码的挂钩。
    • @robotadam - 我认为他的意思是 application:didReceiveRemoteNotification 只有在通知进来时应用程序处于前台时才会被调用。
    • @robotadam,我需要你的帮助。我已经使用 Urban Airship 在 android 中实现了推送通知。我已发送示例文本消息以推送并成功将这些消息发送到所有注册设备。我想知道,如何传递 RSS 提要更新通知。我曾尝试在该 Urban Airship 提要中注册一些 RSS 提要 URL,但它无法正常工作。那么如何在 UA 中提供 RSS 提要 URL?请指导我。
    • 这确实不是获得支持的最佳场所。如果您在使用 RSS 提要时遇到问题,请在我们的支持系统中提出请求。
    【解决方案2】:

    当应用程序未运行或已被系统终止并通过通知启动应用程序时:

    在这种情况下,您必须获取通知字典(它本身就是 launchOptions 的值):

    http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006786-CH3-SW18

    我想代码会是这样的:

     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    
         NSDictionary *remoteNotification = (NSDictionary *) [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
         if (remoteNotification != nil) {
               NSString *message = [remoteNotification descriptionWithLocale:nil indent: 1];
         }    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      相关资源
      最近更新 更多