$cordovaCamera.getPicture 在 ios 11 中不起作用
$cordovaCamera.getPicture does not work in ios 11
我正在使用部署在 ipad 运行 上的 ionic v1 应用程序 ios 11。当我尝试 运行 ipad 中的应用程序时] 然后点击相机按钮,没有任何反应。它保持原样。我试图寻找与 ios 10 类似的问题,并为 info.plst 文件添加了相关标签,还添加了跨框架安全绕过。我环顾四周,但无法解决这个问题。只有在尝试了所有可能的解决方案之后,我才提出这个问题,这些解决方案是针对 $cordovaCamera 不适用 ios 10 的。即使我尝试使用 navigator.camera.getPicture() 而不是 $cordovaCamera.getPicture( ) 但那也不起作用。
在我看来我有
<a ng-click="takePicture()" style="color:#fff;">
在我的控制器中
$scope.takePicture = function (options) {
var options = {
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
quality: 100,
targetWidth: 300,
targetHeight: 300,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
console.log('here');
$scope.pictureUrl = "data:image/jpeg;base64," + imageData;
console.log(imageData);
$scope.img_update = 1;
}, function(err) {
console.log(err);
});
};
在控制器中我也注入了$cordovaCamera。
在index.html中我添加了
<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready file:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
在 config.xml 我在平台内添加了这些标签 ios
<plugin name="cordova-plugin-camera" spec="~2.3.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="The app would like to access the camera when you attach photos to content." />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="The app would like to access the photo library when you attach images to content." />
</plugin>
<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 to 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 to photo library access to save pictures there</string>
</edit-config>
更新最新的 ios 和 android 版本,然后开始执行以下步骤。
步骤 1) 运行 这个命令
ionic cordova plugin rm camera
ionic cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="your usage message"
第 2 步)像这样添加选项
var options = {
// Size
quality: 80,
targetWidth: 1024,
targetHeight: 768,
// Actions
allowEdit: false,
correctOrientation: false,
saveToPhotoAlbum: false,
// iOS
popoverOptions: CameraPopoverOptions,
// Basic
encodingType: Camera.EncodingType.JPEG,
sourceType: Camera.PictureSourceType.CAMERA,
destinationType: this.platform.is('ios') ? Camera.DestinationType.FILE_URI : Camera.DestinationType.DATA_URL,
};
你完成了。
我正在使用部署在 ipad 运行 上的 ionic v1 应用程序 ios 11。当我尝试 运行 ipad 中的应用程序时] 然后点击相机按钮,没有任何反应。它保持原样。我试图寻找与 ios 10 类似的问题,并为 info.plst 文件添加了相关标签,还添加了跨框架安全绕过。我环顾四周,但无法解决这个问题。只有在尝试了所有可能的解决方案之后,我才提出这个问题,这些解决方案是针对 $cordovaCamera 不适用 ios 10 的。即使我尝试使用 navigator.camera.getPicture() 而不是 $cordovaCamera.getPicture( ) 但那也不起作用。
在我看来我有
<a ng-click="takePicture()" style="color:#fff;">
在我的控制器中
$scope.takePicture = function (options) {
var options = {
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
quality: 100,
targetWidth: 300,
targetHeight: 300,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
console.log('here');
$scope.pictureUrl = "data:image/jpeg;base64," + imageData;
console.log(imageData);
$scope.img_update = 1;
}, function(err) {
console.log(err);
});
};
在控制器中我也注入了$cordovaCamera。
在index.html中我添加了
<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready file:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
在 config.xml 我在平台内添加了这些标签 ios
<plugin name="cordova-plugin-camera" spec="~2.3.0">
<variable name="CAMERA_USAGE_DESCRIPTION" value="The app would like to access the camera when you attach photos to content." />
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value="The app would like to access the photo library when you attach images to content." />
</plugin>
<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 to 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 to photo library access to save pictures there</string>
</edit-config>
更新最新的 ios 和 android 版本,然后开始执行以下步骤。
步骤 1) 运行 这个命令
ionic cordova plugin rm camera
ionic cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="your usage message" --variable PHOTOLIBRARY_USAGE_DESCRIPTION="your usage message"
第 2 步)像这样添加选项
var options = {
// Size
quality: 80,
targetWidth: 1024,
targetHeight: 768,
// Actions
allowEdit: false,
correctOrientation: false,
saveToPhotoAlbum: false,
// iOS
popoverOptions: CameraPopoverOptions,
// Basic
encodingType: Camera.EncodingType.JPEG,
sourceType: Camera.PictureSourceType.CAMERA,
destinationType: this.platform.is('ios') ? Camera.DestinationType.FILE_URI : Camera.DestinationType.DATA_URL,
};
你完成了。