1

我已经使用 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];
      }

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

请指导我!

谢谢

4

2 回答 2

4

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

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

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

于 2010-08-13T16:12:22.833 回答
1

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

在这种情况下,您必须获取通知字典(它本身就是 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];
     }    
}
于 2010-08-15T04:26:01.457 回答