0

我是 ios 和 PNS 的新手,我正在处理推送通知,基于此我在通知中获取 URL,我需要将图像显示到图像视图中。我成功获得了 PNS 也使用有效负载获得了 URL,但它没有显示在另一个类的图像视图中下面是我正在使用的代码

  - (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateActive) // If app is running and you got notification then show it 
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Did receive a Remote Notification" message:[NSString stringWithFormat:@"You Have a Notification :\n%@",userInfo[@"aps"][@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

    [alertView show];
}
NSLog(@"Payload: %@", userInfo);
imageURL =  userInfo[@"aps"][@"alert"];
MainViewController *mv =  [[MainViewController alloc] init];
[mv.ansinage setImage:[UIImage imageNamed:@"cartoon.png"]]; // Right now i am setting image in resource but still not setting in mainviewcontrller when i am open app

}
4

1 回答 1

0
-(void) sshowansimage:(NSString *) strImageURL{

NSURL *imageURL = [NSURL URLWithString:strImageURL];
NSLog(@"coming URL is %@", strImageURL);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
    NSData *imageData = [NSData dataWithContentsOfFile:strImageURL];
    [self performSelectorOnMainThread:@selector(showImage:) withObject:imageData waitUntilDone:YES];
});

}

-(void)showImage:(NSData*)imageAsData
{
NSLog(@"IN image view mthhod data is %d",imageAsData.length);
ansinage.image = [UIImage imageWithData:imageAsData];

}
于 2013-11-18T09:05:42.637 回答