2010-08-11 79 views
1

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

这里我的示例代码,

- (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,我不能得到的字典中的值,它总是空值。是否有可能在此方法中获取字典值(Notification)。

 - (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

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

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

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

+0

+1,@robotadam,比ks的答复。看到我更新的问题,请提到我做错了什么。谢谢。 – Pugal 2010-08-14 10:23:45

+0

我不确定你现在的问题是什么 - 你有来自推送通知的数据,是的?剩下的看起来像是一个钩入你的代码的其余部分。 – robotadam 2010-08-14 15:12:28

+0

@robotadam - 我想他是说应用程序:didReceiveRemoteNotification只是在应用程序在前台进行通知时才被调用。 – 2010-08-15 04:17:14

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]; 
    }  
}