2013-02-21 16 views
13

मेरे पास एक ऐप है जिसमें मैं कैमरे के साथ एक तस्वीर लेता हूं और उस छवि को मूल गैलरी में संग्रहीत करता हूं। लेकिन अगर ऐप के पास इसकी अनुमति नहीं है, तो मैं चाहता हूं कि उपयोगकर्ता उसे जान सके। तो मैं इसे कैसे देखूं?मैं कैसे जांच सकता हूं कि मेरे ऐप में फोन गैलरी तक पहुंच है

वैसे:

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); 

उत्तर

29

आप ALAssetLibrary की स्थिति की जांच करने के लिए सुनिश्चित करें कि आप AssetsLibrary/AssetsLibrary.h आपकी फ़ाइल में शामिल कर दिया है की जरूरत है

ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus]; 

// ALAuthorizationStatusAuthorized या ALAuthorizationStatusDenied जैसे

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

    } 
+0

क्या यह सभी आईओएस पर काम करता है? धन्यवाद बीटीडब्ल्यू। – gabrjan

+0

यदि आपको एलास्सेट लाइब्रेरी दिखाई देती है तो आपको आईओएस 5 + पर काम करना चाहिए, तो आप देखेंगे कि इसमें आईओएस 5 + – nsgulliver

+0

के लिए एक और सवाल है जिसके लिए मुझे फ्रेमवर्क की आवश्यकता है? – gabrjan

3

नोट:: मैं के साथ गैलरी में छवि को संग्रहित IOS 6 केवल

यह आप

[ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized; 

के अन्य मूल्यों के लिए क्या देख रहे है प्रमाणीकरणस्टैटस

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

इस iOS6 केवल क्यों है? मुझे सभी जोस की ज़रूरत है, लेकिन मुझे यही चाहिए कि मुझे – gabrjan

+0

प्रमाणीकरण की आवश्यकता है स्टेटस विधि आईओएस 6.0 और बाद में उपलब्ध है। – msk

+0

तो मुझे पिछले संस्करणों के साथ क्या करना चाहिए? – gabrjan

3

आप उपयोग कर रहे हैं तस्वीरें ढांचे के लिए स्थिति की जाँच चूंकि अलास्सेट पुस्तकालयों को आईओएस 9 से हटा दिया गया है, इसलिए आप गैलरी एक्सेस की जांच के लिए PHAuthorizationStatus का उपयोग कर सकते हैं। आपको फोटो फ्रेमवर्क आयात करने की भी आवश्यकता है।

#import <Photos/Photos.h> 

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

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

स्विफ्ट 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 
    } 
} 
संबंधित मुद्दे