如何从app委托类打开iphone的图像库

时间:2013-11-18 12:17:18

标签: ios iphone objective-c appdelegate

您好我想从app delegates类打开图片库。我打开PNS后我正在接收推送通知我想打开iphone的图像库,

这是我的代码 -

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (application.applicationState == UIApplicationStateActive) 
{
    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"];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
     MainViewController *vC=[[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
     self.window.rootViewController=vC;
     [vC  sshowansimage:imageURL];
}
else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
{


     //NSString *imagePath = [path stringByAppendingString:file];

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

 }

-(void)showImage:(NSData*)imageAsData

{
NSLog(@"IN image view mthhod data is %d",imageAsData.length);
UIImage *image=[UIImage imageWithData:imageAsData];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

 }

1 个答案:

答案 0 :(得分:0)

而是做这件事ios 7为

引入新方法

<强>应用:didReceiveRemoteNotification:fetchCompletionHandler:

告诉应用程序已发送推送通知,表明有数据要提取。

如果您的应用支持远程通知后台模式,请实施此方法。该方法旨在作为应用程序的手段,以最小化用户看到推送通知和显示关联数据的应用程序之间经过的时间。当推送通知到达时,系统会向用户显示通知并在后台启动应用程序(如果需要),以便可以调用此方法

参考 - Apple Doc