2017-08-03 120 views
0

我正在使用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

回答

0

我有同樣的問題。

我最終使用https://github.com/dpa99c/cordova-diagnostic-plugin來檢查權限狀態。用一個按鈕彈出一個Popup。當用戶關閉權限對話框時,他必須通過點擊按鈕來關閉彈出窗口。然後我再次檢查權限狀態。這不是一個解決方案,它只是一個解決方法。有點醜但有用。

你自己找到了解決方案嗎?

0

我在我原來的問題接近...不得不修改它爲以下內容:

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成功/失敗回調。有點混亂,但它的作用像魅力。