2013-02-21 13 views

Odpowiedz

29

Trzeba sprawdzić status ALAssetLibrary upewnij się że masz AssetsLibrary/AssetsLibrary.h zawarte w pliku

ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus]; 

// sprawdzenie statusu dla ALAuthorizationStatusAuthorized lub ALAuthorizationStatusDenied np

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

    } 
+0

Czy działa na wszystkich iOS? Dzięki Btw. – gabrjan

+0

to powinno działać na ios5 +, jeśli widzisz ALAssetLibrary, to zauważysz, że ma wsparcie dla ios5 + – nsgulliver

+0

jeszcze jedno pytanie, które ramy są mi potrzebne? – gabrjan

3

Uwaga: iOS 6 Tylko

Czy tego szukasz

[ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized; 

innych wartości AutoryzacjaStatus to

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. 
+0

dlaczego jest tylko to iOS6? Potrzebuję wszystkich joss, ale to jest to, czego potrzebuję – gabrjan

+0

metoda authorizationStatus jest dostępna w iOS 6.0 i nowszych wersjach. – msk

+0

Więc co mam zrobić z wcześniejszymi wersjami? – gabrjan

3

Jeśli używasz zdjęcia ramach ponieważ biblioteki ALAsset są przestarzałe z ios 9, możesz użyć PHAuthorizationStatus, aby sprawdzić dostęp do galerii. Musisz również zaimportować frameworki zdjęć.

#import <Photos/Photos.h> 

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

    if (authorizationStatus == PHAuthorizationStatusAuthorized) { 
     hasGalleryPermission = YES; 
    } 
    return hasGalleryPermission; 
} 
0

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 
    } 
} 
Powiązane problemy