In iOS development, it is often necessary to call the camera to scan something like two-dimensional, before calling, you should first determine whether the current device's camera is available;
Directly below the code: (the wording in Swift)
1 classWncommontool:nsobject {2 /**3 4 determine if the current device's camera is available5 6 : Returns: Whether the camera of the current device is available7 8 */9 Ten classFunc iscameraavailable ()bool{ One A returnUiimagepickercontroller.iscameradeviceavailable (. Rear) && - - uiimagepickercontroller.issourcetypeavailable (. Camera) the } - -}
Use the following method (in Swift):
1 //MARK: scanning QR code2 3 func scanqr () {4 5 ifwncommontool.iscameraavailable () {6 7 //dosomething8 9}Else{Ten OneUialertview (title:"Warm Tips", Message:"Current device camera is not available",Delegate: Self, Cancelbuttontitle:"Determine"). Show () A } - -}
Determine if the current device's camera is available in IOS