【问题标题】:cordova angularjs force app to pause waiting on user permission科尔多瓦 angularjs 强制应用暂停等待用户许可
【发布时间】:2018-01-11 09:51:35
【问题描述】:

我正在使用 cordova-firebase-plugin,iOS 上推送通知的要求之一是授予权限,问题是使用 cordova-firebase-plugin grantPermission 没有正确的成功/错误回调 -因此,当 grantPermission 被调用时,它会向用户弹出权限请求,但在后台应用程序会继续加载。

插件权限调用是一个没有回调的基本函数:

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 权限时实现应用程序初始化暂停吗?

最后,无论用户选择、授予或拒绝权限,status 始终是null

【问题讨论】:

    标签: ios angularjs cordova callback user-permissions


    【解决方案1】:

    我遇到了同样的问题。

    我最终使用https://github.com/dpa99c/cordova-diagnostic-plugin 来检查权限状态。弹出一个带有按钮的弹出窗口。当用户关闭权限对话框时,他必须通过单击按钮来关闭弹出窗口。然后我再次检查权限状态。这不是一个解决方案,它只是一种解决方法。有点难看但有效。

    您自己找到解决方案了吗?

    【讨论】:

      【解决方案2】:

      我原来的问题很接近...不得不将其修改为以下内容:

        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 成功/失败回调。有点杂乱无章,但它就像魅力一样。

      【讨论】:

        猜你喜欢
        • 2016-04-27
        • 2018-10-02
        • 1970-01-01
        • 2017-04-02
        • 1970-01-01
        • 2020-09-10
        • 2017-06-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多