在 ios sdk 中显示来自推送通知的图像
Posted
技术标签:
【中文标题】在 ios sdk 中显示来自推送通知的图像【英文标题】:SHow image from Push notification in ios sdk 【发布时间】:2013-11-07 12:50:31 【问题描述】:我是 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
【问题讨论】:
您可以将图像引用到 MainViewController。以你的方式是不可能的...... 你能再解释一下吗 【参考方案1】:-(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];
【讨论】:
以上是关于在 ios sdk 中显示来自推送通知的图像的主要内容,如果未能解决你的问题,请参考以下文章