cordova angularjs强制应用程序暂停等待用户权限
问题描述:
我正在使用cordova-firebase-plugin,iOS上推送通知的要求之一是授予权限,问题在于使用cordova-firebase-plugin grantPermission
没有一个适当的成功/错误回调 - 因此,当grantPermission被调用时,它将权限请求弹出给用户,但在后台应用程序继续加载。cordova angularjs强制应用程序暂停等待用户权限
该插件允许调用没有回调基本功能:
window.FirebasePlugin.grantPermission();
我需要暂停应用程序加载和仅在用户授权之后继续/拒绝的权限请求。下面是我尝试在我的应用程序的应用程序初始化部分可以这样做:
function iosPush() {
var q = $q.defer() ;
if (/(iPad|iPhone|iPod)/i.test(navigator.userAgent)) {
window.FirebasePlugin.grantPermission(function(status) {
q.resolve(status) ;
},function(err) {errMgmt("ctrl/init",35,"iOS Push ask Permission error: "+err) });) ;
} else {
q.resolve("Android") ;
}
return q.promise ;
}
iosPush().then(function(status) {
return getLocationAuth()
}).then(function(status) {
...do other stuff...
}) ;
我试图暂停的应用程序,虽然不能正常工作。有人可以协助或指出如何在请求iOS权限时实现app init暂停吗?
最后,无论用户选择什么,授予或拒绝的权限,status
总是null
答
我有同样的问题。
我最终使用https://github.com/dpa99c/cordova-diagnostic-plugin来检查权限状态。用一个按钮弹出一个Popup。当用户关闭权限对话框时,他必须通过点击按钮来关闭弹出窗口。然后我再次检查权限状态。这不是一个解决方案,它只是一个解决方法。有点丑但有用。
你自己找到了解决方案吗?
答
我在我原来的问题接近...不得不修改它为以下内容:
function iosPush() {
var q = $q.defer() ;
if (/(iPad|iPhone|iPod)/i.test(navigator.userAgent)) { // 1st hasPerm
window.FirebasePlugin.hasPermission(function(data){
if (data.isEnabled == false) {
window.FirebasePlugin.grantPermission(function(status) { // if no, grant
// Permission Granted or notGranted...need to check again.
window.FirebasePlugin.hasPermission(function(data){
// 2nd hasPerm, if changed, set internal db
var oldPushEnabled = getDB('dev_pushEnabled') ;
if (data.isEnabled == true) {
var pushIsEnabled = 1 ;
} else {
var pushIsEnabled = 0 ;
}
if (oldPushEnabled != pushIsEnabled) {
setDB('dev_pushEnabled',pushIsEnabled) ; // set local app db value
q.resolve("PushStatusNotChanged") ; // push enable status has changed
} else {
q.resolve("PushStatusChanged") ; // push enable status has not changed
}
}) ; // close 1st hasPermission
},function(error) {
// Permission NOT GRANTED
q.resolve("PushNotGranted") ;
}) ; // grantPermission
} else {
q.resolve("PushGranted") ; // authorization was previously granted
}
}) ; // close 2nd hasPermission
} else {
q.resolve("Android") ;
}
return q.promise ;
}
iosPush().then(function(status) {
return getLocationAuth()
}).then(function(status) {
...do other stuff...
}) ;
在功能双hasPermission
充当grantPermission成功/失败回调。有点混乱,但它的作用像魅力。