我是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
}
答案 0 :(得分: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];
}