iPhone Urban Airship发布选项问题

时间:2011-06-02 22:38:11

标签: iphone notifications push urbanairship.com

我有一个非常简单的问题,搜索并没有让我得到答案。在我的应用程序中:didFinishLaunchingWithOptions方法我执行以下操作来恢复程序未运行时进入的通知:

 //Init Airship launch options
 NSMutableDictionary *takeOffOptions = [[[NSMutableDictionary alloc] init] autorelease];
 [takeOffOptions setValue:launchOptions forKey:UAirshipTakeOffOptionsLaunchOptionsKey];
 [UAirship takeOff:takeOffOptions];
 [UAPush shared].delegate = self;
 [[UAPush shared] resetBadge];

 // Register for notifications through UAPush for notification type tracking
 [[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                      UIRemoteNotificationTypeSound |
                                                      UIRemoteNotificationTypeAlert)];

当程序正在运行时(在前台或后台)我可以恢复我的飞艇警报:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
 NSLog(@"\nReceived remote notification:\n%@\n\n", userInfo);

 [[UAPush shared] handleNotification:userInfo applicationState:application.applicationState];
 [[UAPush shared] resetBadge]; // zero badge after push received

 NSString *alertMessage = [[userInfo objectForKey:@"aps"] valueForKey:@"alert"];
}

我的问题是:当程序在前台或后台运行时,从程序未运行时发送的消息中的launchOptions,我可以执行什么命令序列来从userInfo中提取在alertMessage中获取的相同信息?在此先感谢:)

1 个答案:

答案 0 :(得分:7)

NSDictionary * userInfo = [launchOptions valueForKey:@“UIApplicationLaunchOptionsRemoteNotificationKey”];

NSDictionary * apsInfo = [userInfo objectForKey:@“aps”];

NSString * alertMsg = [apsInfo objectForKey:@“alert”];