2016-02-29 110 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