简体   繁体   English

如何从应用程序委托类打开iPhone的图片库

[英]How to open Image Library of iphone from app delegate class

Hello i want to open image library from app delegates class. 您好,我想从应用程序委托类中打开图像库。 I am receiving push notification after opening that PNS i want to open image library of iphone , 打开PNS我要打开iphone图像库后,我收到推送通知。

here is my code - 这是我的代码-

- (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);

 }

Rather doing this thing ios 7 Introduce new method for 而是这样做iOS 7引入了新的方法

application:didReceiveRemoteNotification:fetchCompletionHandler: 应用程序:didReceiveRemoteNotification:fetchCompletionHandler:

Tells the app that a push notification arrived that indicates there is data to be fetched. 告知应用程序已到达的推送通知,指示有要提取的数据。

Implement this method if your app supports the remote-notification background mode. 如果您的应用支持远程通知后台模式,请实施此方法。 This method is intended as a means for apps to minimize the time that elapses between the user seeing a push notification and the app displaying the associated data. 此方法旨在作为应用程序的一种方式,以最大程度地减少用户看到推送通知与应用程序显示关联数据之间的时间。 When a push notification arrives, the system displays the notification to the user and launches the app in the background (if needed) so that it can call this method 当推送通知到达时,系统会向用户显示通知,并在后台启动应用程序(如果需要),以便可以调用此方法

Reference - Apple Doc 参考-Apple Doc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM