如何从照片库获取最后一张照片的路径?

时间:2013-11-01 18:39:30

标签: ios objective-c instagram

我正在使用此方法进行屏幕捕获:

    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage*theImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(theImage, nil, nil, nil);

我希望获得该照片的路径,以便我可以将其与Instagram方法一起使用

  NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", lastphotoTaken]];
//    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", lastphotoTaken]];

self.dic.UTI = @"com.instagram.exclusivegram";
self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
self.dic.annotation = [NSDictionary dictionaryWithObject:@"Here Give what you want to share" forKey:@"InstagramCaption"];
[self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];

感谢名单

1 个答案:

答案 0 :(得分:1)

无法使用以下方式获取资产网址:

UIImageWriteToSavedPhotosAlbum(theImage, nil, nil, nil);

相反,您可以使用:

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum:[theImageCGImage] orientation:(ALAssetOrientation)[theImageimageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error)
    {  
        NSLog(@"Ooops!");  
    }
    else
    {  
        NSLog(@"Saved URL : %@", assetURL);  
    }  
}];  
[library release];
相关问题