Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How may I check if my app has access to phone gallery

I have an app in which I take a picture with the camera and store that image into the native gallery. But if the app doesn't have permission for that, I want the user to know that. So how do I check it?

By the way: I store the image into the gallery with:

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
like image 648
gabrjan Avatar asked Feb 21 '13 13:02

gabrjan


People also ask

How do I find out what apps have access to my gallery?

Open your Android's Settings app and go to Privacy, followed by the Permission manager option. There, you'll see all the different types of permissions. For example, tap on the camera option. You'll see a list of all the apps that have permission to access your camera there.

Which apps have access to my phone?

You can review the type of account access a third party has as well as the Google services it has access to. Go to the Security section of your Google Account. Under “Third-party apps with account access,” select Manage third-party access. Select the app or service you want to review.

Will apps have access to your photos?

An app may request access to your photos if the app supports photo uploads. For example, when installing the Google Drive app, it will ask for photo access. This is because the app supports photo storage and will grab you photos for storing. This is an example of a safe and legitimate photo access request.


4 Answers

You need to check the status of ALAssetLibrary make sure you have AssetsLibrary/AssetsLibrary.h included in your file

  ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

// check the status for ALAuthorizationStatusAuthorized or ALAuthorizationStatusDenied e.g

    if (status != ALAuthorizationStatusAuthorized) {
        //show alert for asking the user to give permission

    }
like image 92
nsgulliver Avatar answered Oct 20 '22 06:10

nsgulliver


Swift 3

import photos

PHPhotoLibrary.requestAuthorization { status in
     switch status {
     case .authorized:
          self.processSnapShotPhotos()
     case .restricted:
          print("handle restricted")
     case .denied:
          print("handle denied")     
     default:
       // place for .notDetermined - in this callback status is already determined so should never get here
            break
     }
}
like image 24
CodeOverRide Avatar answered Oct 20 '22 04:10

CodeOverRide


If you are using photos framework since ALAsset libraries are deprecated from ios 9 you can use PHAuthorizationStatus to check gallery access. You need to import photos framework as well.

  #import <Photos/Photos.h>

- (BOOL)hasGalleryPermission
{
    BOOL hasGalleryPermission = NO;
    PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus];

    if (authorizationStatus == PHAuthorizationStatusAuthorized) {
        hasGalleryPermission = YES;
    }
    return hasGalleryPermission;
}
like image 4
Gihan Avatar answered Oct 20 '22 04:10

Gihan


Note: iOS 6 Only

Is this what you are looking for

[ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized;

Other values of authorizationStatus are

ALAuthorizationStatusRestricted,        // This application is not authorized to access photo data.
                                            // The user cannot change this application’s status, possibly due to active restrictions
                                            //  such as parental controls being in place.
    ALAuthorizationStatusDenied,            // User has explicitly denied this application access to photos data.
    ALAuthorizationStatusAuthorized         // User has authorized this application to access photos data.
like image 3
msk Avatar answered Oct 20 '22 04:10

msk