我有一个非常简单的问题,但搜索没有让我找到答案。在我的 application: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"];
}
我的问题是这样的:当程序在前台或后台运行时,我可以执行什么命令序列来从 userInfo 中提取从 AlertMessage 中获得的相同信息,从程序未运行时发送的消息中的 launchOptions 中提取相同的信息?预先感谢:)
最佳答案
NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alertMsg = [apsInfo objectForKey:@"alert"];
关于iPhone Urban Airship 发射选项问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6221183/