2015-08-31 11 views
9

पर पहुंच का अनुरोध करें मेरे पास एक क्यूआर कोड स्कैनर वाला ऐप है जो ठीक काम करता है, लेकिन आईओएस 8 पर कैमरे की डिफ़ॉल्ट पहुंच "अस्वीकार" है। इसलिए मुझे सेटिंग्स में जाना है और मैन्युअल रूप से कैमरे का उपयोग करने के लिए ऐप एक्सेस देना है। मैं प्रॉम्प्ट कैसे बना सकता हूं जो कुछ कहता है "क्या आप इस ऐप को कैमरे का उपयोग करने के लिए एक्सेस देना चाहते हैं"?आईओएस: कैमरा

यहां कैमरा अनुमतियों के लिए मेरे कोड की जांच का नमूना है और फिर उपयोगकर्ता ने उन्हें अनुमति नहीं दी है तो अनुमति का अनुरोध किया है। हालांकि, अनुमति देने का लिंक कभी दिखाई नहीं देता है और अंत में केवल UIAlertView दिखाता है। जब मैं परीक्षण करता हूं तो स्थिति वास्तव में दी जाती है, तो क्या कोई कारण है कि यह अनुमति मांग नहीं रहा है? धन्यवाद!

इसके अलावा मेरे पास #import AVFoundation/AVFoundation.h है इसलिए यह मुद्दा नहीं है।

-(void) checkCameraAuthorization { 

AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 

if(status == AVAuthorizationStatusAuthorized) { // authorized 
    NSLog(@"camera authorized"); 
} 
else if(status == AVAuthorizationStatusDenied){ // denied 
    if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)]) { 
     [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { 
      // Will get here on both iOS 7 & 8 even though camera permissions weren't required 
      // until iOS 8. So for iOS 7 permission will always be granted. 

      NSLog(@"DENIED"); 

      if (granted) { 
       // Permission has been granted. Use dispatch_async for any UI updating 
       // code because this block may be executed in a thread. 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        //[self doStuff]; 
       }); 
      } else { 
       // Permission has been denied. 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Authorized" message:@"Please go to Settings and enable the camera for this app to use this feature." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
       [alert show]; 
      } 
     }]; 
    } 
} 
else if(status == AVAuthorizationStatusRestricted){ // restricted 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Authorized" message:@"Please go to Settings and enable the camera for this app to use this feature." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
    [alert show]; 
} 
else if(status == AVAuthorizationStatusNotDetermined){ // not determined 

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { 
     if(granted){ // Access has been granted ..do something 
      NSLog(@"camera authorized"); 
     } else { // Access denied ..do something 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not Authorized" message:@"Please go to Settings and enable the camera for this app to use this feature." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
      [alert show]; 
     } 
    }]; 
} 
} 
+0

यहाँ उत्तर दिया: http://stackoverflow.com/questions/24229422/accessing-the-settings-app-from-your -app-in-ios-8 –

उत्तर

13

लगता है जैसे ऐप को कैमरे तक पहुंच से वंचित कर दिया गया है। इस मामले में, आप फिर से संकेत नहीं दे सकते। आप केवल प्रति इंस्टॉल करने के बाद उपयोगकर्ता को पहुंच के लिए संकेत दे सकते हैं। इसके बाद आपको उपयोगकर्ता को सेटिंग्स पर निर्देशित करने की आवश्यकता होगी।

जहां कैमरा (iOS8 पर) इस के साथ सक्रिय किया जा सकता अपनी सेटिंग में उपयोगकर्ता भेजें:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 

आप परीक्षण कर रहे हैं, तो स्थापित फोन से एप्लिकेशन को हटाने की कोशिश और उसके बाद और इसे फिर से चलाते हैं। यह आपको AVAuthorizationStatusNotDetermined स्थिति में वापस रखता है।

+1

एक साफ छोटी चाल है, मुझे नहीं पता था कि मैं उपयोगकर्ता को अपने ऐप से सेटिंग्स पर रीडायरेक्ट कर सकता हूं। यह काम करेगा, मैं सिर्फ एक चेतावनी में निर्देशों को बताने का बड़ा प्रशंसक नहीं था। धन्यवाद! ** क्या कोई तरीका है कि मैं सेटिंग ऐप खोलने के बजाय उन्हें सीधे ऐप की सेटिंग्स पर भेज सकता हूं? –

+1

वर्तमान में, ऐप हटा दिए जाने पर भी डिवाइस 'गोपनीयता' याद रखता है। तो सभी ** डिवाइस की गोपनीयता सेटिंग्स को रीसेट करने के अलावा, मूल पॉपअप को फिर से प्राप्त करने का कोई तरीका नहीं है। – bauerMusic

संबंधित मुद्दे