API Cloudダイナミック権限の完全なモデルコード


レススの下に追加 manifist.xmlファイル


    
 
カスタムjsメソッド 

/**
 *	  APP       
 * @param array   one_per  	-     ['camera','location']
 */
function hasPermission(one_per) {
    var rets = api.hasPermission({
        list: one_per
    });

	//         
	var temp = new Array();
	var status = true;
	for (var obj in rets) {
		var granted = rets[obj].granted;
		var names = rets[obj].name;
		if (granted == false) {
			temp.push(names);
			status = false;
		}
	}
	//    ,        
    return  { "status": status, "perms": temp };
}

/**
 *	    
 * @param array		one_per  	-     ['camera','location']
 * @param function  callback  	-     
 */
function reqPermission(one_per,callback) {
    api.requestPermission({
        list: one_per,
        code: 100001
    }, function(ret, err) {
		//      
		var list = ret.list;
		for (var i in list) {
			//         ,   
			if (list[i].granted == false) {
				api.toast({
				    msg: '    ,         ',
				    duration: 2000,
				    location: 'bottom'
				});
				return false;
			}
		}

        if (callback) {
            callback();
            return;
        }
    });
}

/**
 *             ,          
 * @param array		perm	  	-     ['camera','location']
 * @param function  callback  	-     
 */
function confirmPer(perm, callback) {
	//     
	//calendar  ,camera  ,contacts   ,location    ,microphone   
	//phone  ,sensor     ,sms  ,storage    ,photos  
	console.log(perm);

	//ios      
	if(api.systemType == 'ios'){
		// callback();
		// return false;
	}
	//       ,   ,(      )
    if (perm.indexOf(",") != -1) {
        var perms = perm.split(',');
    } else {
		var perms = new Array(perm);
    }

	//             
    var has = hasPermission(perms);
	console.log(JSON.stringify(has));
    if (!has.status) {
		//    
        reqPermission(has.perms,callback);
        return false;
    }

	callback();
    return true;
}
 
呼び出しの例:
confirmPer('camera,sensor',function(){
                api.alert({
                    title: '      。',
                    msg: 'testmsg',
                }, function(ret, err){

                });
            });