Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Defines a callback for the notifications permission #207

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions PermissionScope/PermissionScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void
/// View controller to be used when presenting alerts. Defaults to self. You'll want to set this if you are calling the `request*` methods directly.
public var viewControllerForAlerts : UIViewController?

// If defined, this callback will be called so that the application can handle the request for notifications itself, if not set, Permissionscope will call UIApplication.shared.registerUserNotificationSettings
public var notificationRequestCallback:((NotificationsPermission?) -> Void)?
/**
Checks whether all the configured permission are authorized or not.

Expand Down Expand Up @@ -640,10 +642,14 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void

notificationTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(finishedShowingNotificationPermission), userInfo: nil, repeats: false)

UIApplication.shared.registerUserNotificationSettings(
UIUserNotificationSettings(types: [.alert, .sound, .badge],
categories: notificationsPermissionSet)
)
if let callback = notificationRequestCallback {
callback(notificationsPermission)
} else {
UIApplication.shared.registerUserNotificationSettings(
UIUserNotificationSettings(types: [.alert, .sound, .badge],
categories: notificationsPermissionSet)
)
}
case .unauthorized:
showDeniedAlert(.notifications)
case .disabled:
Expand Down