2013-11-01 2 views
2

я использую этот метод, чтобы принять захват экрана:Как добраться до последней фотографии из библиотеки фотографий?

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

Thanx

ответ

1

Там это не способ получить URL-адрес актива:

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

спасибо, но URL для моего изображения: 'активы-библиотека: //asset/asset.JPG ID = 7D636703-8786-465D-B896-A0A67F0B0CCE и внутр = JPG' как конвертировать это таким образом 'file: // ...' – AsimNet

+0

@AsimNet: вы не можете сделать это с помощью URL-адресов ресурсов. Или хранить изображения в каталоге документов вместо фотобиблиотеки –

Смежные вопросы