-1

i'm using this function to save image in Album :

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

it's work other project but not work in my application and give me error :

Error Domain=ALAssetsLibraryErrorDomain Code=-3310 "Data unavailable" UserInfo={NSLocalizedRecoverySuggestion=Launch the Photos application, NSUnderlyingError=0x14dcec40 {Error Domain=ALAssetsLibraryErrorDomain Code=-3310 "Data unavailable" UserInfo={NSLocalizedRecoverySuggestion=Launch the Photos application, NSUnderlyingError=0x1ab52eb0 {Error Domain=com.apple.photos Code=-3001 "(null)"}, NSLocalizedDescription=Data unavailable}}, NSLocalizedDescription=Data unavailable}

And also app in not in Photos section in Setting : Settings -> Privacy -> Photos.

But not work in my application.

EDIT :

Getting Same error using PHPhotoLibrary

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

                }
                else {

                }
            }];

Error :

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

When i create new project than it working fine, but not in my app ! I also change bundle id to create new app in device, and also reset setting for permission.

iBhavin
  • 1,261
  • 15
  • 30
bhadresh
  • 445
  • 5
  • 15
  • I found this on another thread. This may help solving your problem http://stackoverflow.com/questions/12968486/uiimagewritetosavedphotosalbum-does-not-work-in-ios-6-ipad-3 – Güngör Basa Feb 29 '16 at 08:32

2 Answers2

1

As per the Apple document ALAssetsLibrary

Assets Library framework is deprecated as of iOS 9.0

enter image description here

So, it is better to use PHPhotoLibrary with more advance features.

Try this code:-

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")
        }
    }

Check this for Request Authorisation :- authorizationStatus

Badal Shah
  • 7,541
  • 2
  • 30
  • 65
  • getting same error using PHPhotoLibrary. please see updated question, – bhadresh Feb 29 '16 at 09:32
  • Check it in three place . 1) #import 2) in general -> Linked frameworks and libraries 3) Buildphases -> linkbinary with libraries. – Badal Shah Feb 29 '16 at 10:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104847/discussion-between-badal-shah-and-bhadresh). – Badal Shah Feb 29 '16 at 10:22
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
{




}
shikha kochar
  • 163
  • 1
  • 7
  • 'Error Domain=NSCocoaErrorDomain Code=2047 "Photos Access not allowed (authorization status 0)" UserInfo={NSLocalizedDescription=Photos Access not allowed (authorization status 0)}' – bhadresh Feb 29 '16 at 12:02
  • http://databasefaq.com/index.php/answer/341374/ios-iphone-swift-ios8-ios-swift-creating-app-folder-error – shikha kochar Mar 01 '16 at 05:29