ios, ui, utils: relocated iOS notification permissions to home screen

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
kwingram25 2018-03-26 22:01:33 -07:00 committed by Andrey Shovkoplyas
parent b3ef1ed53a
commit 13c448032c
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
5 changed files with 36 additions and 3 deletions

View File

@ -32,7 +32,6 @@
(.hide react/splash-screen))
:component-did-mount
(fn []
(notifications/request-permissions)
(notifications/on-refresh-fcm-token)
(notifications/on-notification))
:component-will-unmount

View File

@ -212,7 +212,8 @@
:account-finalized
(fn [{db :db} _]
{:db db
:dispatch [:navigate-to-clean :home]}))
:dispatch-n [[:navigate-to-clean :home]
[:request-notifications]]}))
(handlers/register-handler-fx
:update-sign-in-time

View File

@ -176,6 +176,11 @@
(fn [options]
(permissions/request-permissions options)))
(re-frame/reg-fx
::request-notifications-fx
(fn [_]
(notifications/request-permissions)))
(re-frame/reg-fx
::testfairy-alert
(fn []
@ -418,6 +423,11 @@
(fn [_ [_ options]]
{:request-permissions-fx options}))
(handlers/register-handler-fx
:request-notifications
(fn [_ _]
{::request-notifications-fx {}}))
(handlers/register-handler-db
:set-swipe-position
[re-frame/trim-v]

View File

@ -21,6 +21,14 @@
{:label "Logout"
:trigger [:navigate-to :accounts]}
; Push notification settings
{:label "Granted push notifications"
:trigger [:request-notifications-granted]}
{:label "Denied push notifications"
:trigger [:request-notifications-denied]}
;; Tab navigation
{:label "Tap"

View File

@ -16,9 +16,24 @@
(fn [db [_ fcm-token]]
(assoc-in db [:notifications :fcm-token] fcm-token)))
(handlers/register-handler-fx
:request-notifications-granted
(fn [_ _]))
(handlers/register-handler-fx
:request-notifications-denied
(fn [_ _]))
;; NOTE: Only need to explicitly request permissions on iOS.
(defn request-permissions []
(.requestPermissions (.-default rn/react-native-fcm)))
(-> (.requestPermissions (.-default rn/react-native-fcm))
(.then
(fn [_]
(log/debug "notifications-granted")
(dispatch [:request-notifications-granted {}]))
(fn [_]
(log/debug "notifications-denied")
(dispatch [:request-notifications-denied {}])))))
(defn get-fcm-token []
(-> (.getFCMToken (object/get rn/react-native-fcm "default"))