Cordova Ios 应用程序在访问相机时崩溃
Cordova Ios App crashes on Camera Access
我正在 Cordova 中创建一个应用程序 Windows(由于 Mac 不可用)使用 JQuery for IOs 并在 Phonegap 云上远程构建。但问题是当我尝试通过 cordova-plugin-camera[ 从 iPhone(Os v-11.3) 的相机获取图像时=28=] 应用程序崩溃。
config.xml:
<plugin name="cordova-plugin-camera" spec="~2.1.1">
<variable name="CAMERA_USAGE_DESCRIPTION" value="App want to access your camera" />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="App want to access your camera to upload images" />
</plugin>
<platform name="ios">
<icon height="57" platform="ios" src="www/res/icon/ios/icon.png" width="57" />
........
........
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
<string>need camera access to take pictures</string>
</edit-config>
<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
<string>need photo library access to get pictures from there</string>
</edit-config>
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
<edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
<string>need photo library access to save pictures there</string>
</edit-config>
</platform>
JS:
function accessCamera(){
var options = setOptions(Camera.PictureSourceType.CAMERA);
getPic(options);
}
function setOptions(srcType) {
var options = {
// Some common settings are 20, 50, and 100
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
// In this app, dynamically set the picture source, Camera or photo gallery
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true //Corrects Android orientation quirks
}
return options;
}
function getPic(options){
console.log(Camera.PictureSourceType);
console.log("SourceTye: "+options.sourceType);
try{
navigator.camera.getPicture(function cameraSuccess(imageUri) {
// $('#main_img').attr('src', imageUri);
setAndUploadPic(imageUri);
}, function cameraError(error) {
console.debug("Unable to obtain picture: " + error, "app");
}, options);
}catch(err){
// $('#exp').text(err.message);
}
}
但是我一访问相机我的应用程序就崩溃了。
如果您在 xcode 上的模拟器中 运行 并在控制台上查看,您可以看到发生了什么。根据我的经验,问题与 NsCameraUsageDescription 的 plist 设置有关,当应用程序崩溃时,在控制台中存在一个特定的错误。
尝试将此行添加到相机插件的 plugin.xml 而不是上面发布的行:
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>For take user photo and upload photos.</string>
</config-file>
<preference name="PHOTOLIBRARY_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string>For upload photos.</string>
</config-file>
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string>need location access to find things nearby</string>
</config-file>
请更新您的相机插件并检查
<plugin name="cordova-plugin-camera" spec="2.4.1" />
请删除特定插件的更新版本并删除版本号
<plugin name="cordova-plugin-camera">
它将运行 归档。您的插件导致问题。
我正在 Cordova 中创建一个应用程序 Windows(由于 Mac 不可用)使用 JQuery for IOs 并在 Phonegap 云上远程构建。但问题是当我尝试通过 cordova-plugin-camera[ 从 iPhone(Os v-11.3) 的相机获取图像时=28=] 应用程序崩溃。
config.xml:
<plugin name="cordova-plugin-camera" spec="~2.1.1">
<variable name="CAMERA_USAGE_DESCRIPTION" value="App want to access your camera" />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="App want to access your camera to upload images" />
</plugin>
<platform name="ios">
<icon height="57" platform="ios" src="www/res/icon/ios/icon.png" width="57" />
........
........
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<edit-config target="NSCameraUsageDescription" file="*-Info.plist" mode="merge">
<string>need camera access to take pictures</string>
</edit-config>
<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
<string>need photo library access to get pictures from there</string>
</edit-config>
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
<edit-config target="NSPhotoLibraryAddUsageDescription" file="*-Info.plist" mode="merge">
<string>need photo library access to save pictures there</string>
</edit-config>
</platform>
JS:
function accessCamera(){
var options = setOptions(Camera.PictureSourceType.CAMERA);
getPic(options);
}
function setOptions(srcType) {
var options = {
// Some common settings are 20, 50, and 100
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
// In this app, dynamically set the picture source, Camera or photo gallery
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true //Corrects Android orientation quirks
}
return options;
}
function getPic(options){
console.log(Camera.PictureSourceType);
console.log("SourceTye: "+options.sourceType);
try{
navigator.camera.getPicture(function cameraSuccess(imageUri) {
// $('#main_img').attr('src', imageUri);
setAndUploadPic(imageUri);
}, function cameraError(error) {
console.debug("Unable to obtain picture: " + error, "app");
}, options);
}catch(err){
// $('#exp').text(err.message);
}
}
但是我一访问相机我的应用程序就崩溃了。
如果您在 xcode 上的模拟器中 运行 并在控制台上查看,您可以看到发生了什么。根据我的经验,问题与 NsCameraUsageDescription 的 plist 设置有关,当应用程序崩溃时,在控制台中存在一个特定的错误。 尝试将此行添加到相机插件的 plugin.xml 而不是上面发布的行:
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>For take user photo and upload photos.</string>
</config-file>
<preference name="PHOTOLIBRARY_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string>For upload photos.</string>
</config-file>
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string>need location access to find things nearby</string>
</config-file>
请更新您的相机插件并检查
<plugin name="cordova-plugin-camera" spec="2.4.1" />
请删除特定插件的更新版本并删除版本号
<plugin name="cordova-plugin-camera">
它将运行 归档。您的插件导致问题。