OGeek|极客世界-中国程序员成长平台

标题: ios - 如何从照片库中获取最后一张照片的路径? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:07
标题: ios - 如何从照片库中获取最后一张照片的路径?

我正在使用这种方法进行屏幕截图:

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

感谢



Best Answer-推荐答案


无法使用以下方法获取 Assets 网址:

UIImageWriteToSavedPhotosAlbum(theImage, nil, nil, nil);

您可以使用:

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

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

关于ios - 如何从照片库中获取最后一张照片的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19733210/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4