2016-02-29 108 views
-1

我使用這個功能來保存圖像相冊工作:UIImageWriteToSavedPhotosAlbum不與iPad的XCode 7.2

UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:@"Icon-29.png"], self,@selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:) , nil); 

這是工作以外的項目,但在我的應用程序無法正常工作,給我的錯誤:

錯誤域= ALAssetsLibraryErrorDomain代碼= -3310 「數據不可用」 的UserInfo = {NSLocalizedRecoverySuggestion =啓動照片應用程序, NSUnderlyingError = 0x14dcec40 {錯誤域= ALAssetsLibraryErrorDomain 代碼= -3310 「數據不可用」 的UserInfo = {NSLocalizedRecoverySuggestion =啓動照片應用程序, NSUnderlyingError = 0x1ab52eb0 {錯誤域= com.apple.photos代碼= -3001 「(空)」},NSLocalizedDescription =數據不可用}}, NSLocalizedDescription =數據不可用}

而且應用程序中不在Photos部分Setting: 設置 - >隱私 - >照片。

但在我的應用程序中不起作用。

編輯:

獲取使用同樣的錯誤PHPhotoLibrary

  [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
       PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageNamed:@"Icon-29.png"]]; 
      } completionHandler:^(BOOL success, NSError *error) { 
       if (success) { 

       } 
       else { 

       } 
      }]; 

錯誤:

Error Domain=NSCocoaErrorDomain Code=2047 "Photos Access not allowed (authorization status 0)" UserInfo={NSLocalizedDescription=Photos Access not allowed (authorization status 0)} 

當我創建比它做工精細新的項目,但不是在我的應用程序! 我還更改了包ID以在設備中創建新的應用程序,並且還重置了權限設置。

+0

我發現這在另一個線程。這可能有助於解決您的問題http://stackoverflow.com/questions/12968486/uiimagewritetosavedphotosalbum-does-not-work-in-ios-6-ipad-3 –

回答

1

按照蘋果的文檔ALAssetsLibrary

資源庫框架已廢棄的iOS 9.0

所以,最好是使用 PHPhotoLibrary有更先進的功能

enter image description here

試試這個代碼: -

PHPhotoLibrary.requestAuthorization 
{ (PHAuthorizationStatus status) -> Void in 
    switch (status) 
    { 
     case .Authorized: 
      // Permission Granted 
      println("Write your code here") 
     case .Denied: 
      // Permission Denied 
      println("User denied") 
     default: 
      println("Restricted") 
     } 
    } 

選中此爲請求授權: - authorizationStatus

+0

使用PHPhotoLibrary得到相同的錯誤。請看更新的問題, – bhadresh

+0

你有導入photos和photosui框架嗎? –

+0

是它的進口。 – bhadresh

0
Use This Method ... 


-(void) saveimage:(NSString *)imagename 
{ 
    UIImageWriteToSavedPhotosAlbum(self.image, 
            self, 
            @selector(image:didFinishSavingWithError:contextInfo:), 
            nil); 

} 
- (void) image:(UIImage*)image didFinishSavingWithError:(NSError *)error contextInfo:(NSDictionary*)info 
{ 




} 
+0

'這不是工作。' – bhadresh

+0

你是否收到任何錯誤?在didFinishSavingWithError ??? –

+0

'錯誤域= NSCocoaErrorDomain代碼= 2047「照片訪問不允許(授權狀態0)」UserInfo = {NSLocalizedDescription =照片訪問不允許(授權狀態0)}' – bhadresh