Search code examples
iosqr-codeavcapturesession

iOS Extension does not start the avcapturesession for video media capture


I have added the QR code reader code for the ios application Now I want to use the same code which can be used as Today extension in ios. I have used the following code for the application as well as for extension. The application works fine but it doesn't work with the extension.

I have used the code of http://www.appcoda.com/qr-code-ios-programming-tutorial/. But it does not start the _captureSession in the case of extension.


Solution

  • As per apple documentation accessing the camera from extension is restricted.

    https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionOverview.html

    enter image description here

    So it is not possible to use QR reader from extension because it uses iPhone camera.

    If you want to open the QR reader from the today extension launch your app by calling its url scheme

    NSURL *appURL = [NSURL URLWithString:@"YOURAPP_URLSCHEME://openReader"];
    [self.extensionContext openURL:appURL completionHandler:nil];
    

    In containing app, open the QR reader in AppDelegate's openURL: method.