是否可以在didFinishLaunchingWithOptions方法中将有效负载值存储到全局变量中。将来,我需要使用来自javascript函数(phonegap)的这个全局变量。 notificationData是我在.h文件中声明的全局变量。
NSString * notificationData;
在.m文件中didFinishLaunchingWithOptions方法
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BOOL ret = [super application:application didFinishLaunchingWithOptions:launchOptions];
if (launchOptions != nil) {
//opened from a push notification when the app is closed
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo != nil){
[self processRemoteNotification:userInfo];
}
} else {}
return ret;
}
-(void) processRemoteNotification:(NSDictionary *)userInfo{
NSString *ctpayload = [userInfo objectForKey:@"payload"];
notificationData = ctpayload;
}
答案 0 :(得分:0)
为什么只保存有效负载的参考。它是字符串,您可以使用有效负载值分配新字符串:
myString = [[NSString alloc] initWithString:payload];
并使用它。 声明
NSString* myString;
<。>在.h文件中。