这是我的有效载荷
{
aps = {
ImageURL = "http://i.forbesimg.com/media/lists/people/cristiano-ronaldo_416x416.jpg";
alert = testing;
};
}
这是我的代码
NSDictionary *aps = [[NSDictionary alloc] initWithDictionary:[launchOptions objectForKey:@"aps"]];
NSString *text = [aps objectForKey:@"alert"];
NSString *imageUrl = [aps objectForKey:@"ImageURL"];
该代码在didReceivePushNotification中工作,但在didFinishLaunching 中不工作
该代码应该可以工作,尽管它过于复杂且效率低下。没有理由用launchOptions
字典的内容创建一个新字典。
简单地说
NSString *text = ((NSDictionary*)launchOptions[@"aps"])[@"alert"];
NSString *imageURL = ((NSDictionary*)launchOptions[@"aps"])[@"ImageURL"];
或
NSDictionary *aps = (NSDictionary*)launchOptions[@"aps"];
NSString *text = aps[@"alert"];
NSString *imageURL = aps[@["ImageURL"];