这是我的有效载荷

{
    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"];


此代码在didRecievePushNotification中工作,但在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"];

关于ios - NSDictionary在推送通知中返回空字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38468978/

10-09 00:08