PhoneGap BuildでビルドしたiOSアプリで、navigator.camera.getPicture
を呼び出すと、アプリがクラッシュします。
onDeviceReadyが完了した後で、.pic-button
のボタンをタップし、関数openFilePicker()
を呼び出しています。
後述のソースコードfilePicker.jsで、
navigator.camera.getPicture
を呼び出す直前のalert「check point 1」は出力されますが、
成功の処理のalert「get picture」と
失敗の処理のalert「Unable to obtain picture: …」は出力されず、
アプリが落ちます(クラッシュします)。
PCのデスクトップアプリ「PhoneGap」でプロジェクトをrunし、
iPhoneのアプリ「PhoneGapApp」上でアプリを動かした場合は、問題無く動作します。
開発環境、ソースコードは下記のとおりです。
解決策をご存知の方、コメントよろしくお願い致します。
###■開発環境
▼PC
windows 10
▼端末
iPhone 6s Plus
iOS : 10.3.1
▼PhoneGap Build
phonegap-version : cli-7.0.1
https://build.phonegap.com/apps
▼cordova-plugin-camera
version : 4.0.3
古いバージョンもいくつか試しましたが、クラッシュしました。
###■ソースコード
config.xml
lang
1<?xml version='1.0' encoding='utf-8'?> 2<widget id="com.test" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 3 <content src="index.html" /> 4 <preference name="phonegap-version" value="cli-7.0.1" /> 5 <preference name="DisallowOverscroll" value="true" /> 6 <preference name="android-minSdkVersion" value="14" /> 7 <preference name="StatusBarOverlaysWebView" value="false" /> 8 <preference name="StatusBarBackgroundColor" value="#ee6e73" /> 9 <preference name="StatusBarStyle" value="blacktranslucent" /> 10 <access origin="*" /> 11 <allow-intent href="http://*/*" /> 12 <allow-intent href="https://*/*" /> 13 <allow-intent href="tel:*" /> 14 <allow-intent href="sms:*" /> 15 <allow-intent href="mailto:*" /> 16 <allow-intent href="geo:*" /> 17 <platform name="android"> 18 <allow-intent href="market:*" /> 19 </platform> 20 <platform name="ios"> 21 <allow-intent href="itms:*" /> 22 <allow-intent href="itms-apps:*" /> 23 </platform> 24 <plugin name="cordova-plugin-console" spec="~1.0.3" /> 25 <plugin name="cordova-plugin-dialogs" spec="~1.2.1" /> 26 <plugin name="cordova-plugin-whitelist" spec="~1.2.1" /> 27 <plugin name="cordova-plugin-camera" spec="^4.0.3" /> 28 <plugin name="cordova-plugin-file" spec="^6.0.1" /> 29 <plugin name="cordova-plugin-file-transfer" spec="^1.7.1" /> 30 <plugin name="cordova-plugin-device" spec="^2.0.2" /> 31 <engine name="ios" spec="^4.4.0" /> 32</widget>
index.html
lang
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="utf-8" /> 5 <meta name="format-detection" content="telephone=no" /> 6 <meta name="msapplication-tap-highlight" content="no" /> 7 <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" /> 8 9 <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous"> 10 11 <link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css"> 12 <link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css"> 13 <link rel="stylesheet" type="text/css" href="css/style.css" /> 14 15 <script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script> 16 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 17 18 <script type="text/javascript" src="js/filePicker.js"></script> 19 <script type="text/javascript" src="js/index.js"></script> 20 <script type="text/javascript" src="cordova.js"></script> 21 22 <script> 23 app.initialize(); 24 </script> 25 26 <title>filePicker</title> 27</head> 28 29<body> 30 <ons-page> 31 <table class="post-menu"> 32 <tr> 33 <td class="pic-button"><div><img class="icon pic" src="img/icon/picture.svg"></div></td> 34 </tr> 35 </table> 36 </ons-page> 37</body> 38 39</html>
index.js
lang
1var app = { 2 // Application Constructor 3 initialize: function() { 4 this.bindEvents(); 5 }, 6 bindEvents: function() { 7 document.addEventListener('deviceready', this.onDeviceReady, false); 8 }, 9 onDeviceReady: function() { 10 alert('Received Device Ready Event'); 11 console.log('Received Device Ready Event'); 12 } 13}
filePicker.js
lang
1//写真選択画面へ 2$(document).on("click", ".pic-button", function() { 3 openFilePicker(); 4}); 5 6function openFilePicker(selection) { 7 var srcType = Camera.PictureSourceType.PHOTOLIBRARY; 8 var options = setOptions(srcType); 9 10 alert("check point 1"); 11 12 navigator.camera.getPicture(function cameraSuccess(imageUri) { 13 alert("get picture"); 14 alert("imageUri : "+imageUri); 15 }, function cameraError(error) { 16 alert("Unable to obtain picture: " + error, "app"); 17 }, options); 18} 19 20function setOptions(srcType) { 21 var options = { 22 // Some common settings are 20, 50, and 100 23 quality: 50, 24 destinationType: Camera.DestinationType.FILE_URI, 25 // In this app, dynamically set the picture source, Camera or photo gallery 26 sourceType: srcType, 27 encodingType: Camera.EncodingType.JPEG, 28 mediaType: Camera.MediaType.PICTURE, 29 allowEdit: true, 30 correctOrientation: true //Corrects Android orientation quirks 31 } 32 return options; 33}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/22 04:10