Question

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 ,

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

 }
Was it helpful?

Solution

Rather doing this thing ios 7 Introduce new method for

application: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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top