Search code examples
iphoneiosipadqr-codeip-camera

iPad application crashes on starting camera


I am creating an application in which i need to start camera and scan QR code. I am using a class in through which scanner starts. it is fine in iPhone but crashes in iPad. i am using the code

if(![[appDelegate.tabbarcontroller.viewControllers objectAtIndex:1] isMovingFromParentViewController]) { 
    [[appDelegate.tabbarcontroller.viewControllers objectAtIndex:1] popToRootViewControllerAnimated:NO];
}

Solution

  • Using defensive programming in iOS is a very good strategy to prevent crashes.

    About your question, from Apple doc:

    To use an image picker controller containing its default controls, perform these steps:

    Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the “UIImagePickerControllerSourceType” enum.

    Check which media types are available, for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.

    The link iphone-tutorial-better-way-to-check-capabilities-of-ios-devices by Mugunth Kumar provides the info you need to checke against device capabilities.

    Hope it helps.