Closed DimDL closed 8 years ago
Hi @DimDL , thanks for the issue.
I can't reproduce it. The callback is always triggered (either in the simulator or on a device). Can you give me more details please? What's the status of the permission before you request it etc.
Permission doesn't register for remote or local notifications but only configures the User Notification Settings (via registerUserNotificationSettings(_:)
). See the source.
Thus only application(_:didRegisterUserNotificationSettings:)
will be called, but not application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
.
Hi @delba, thanks for your input.
I've tested a little bit more, and issue reproduces, but only the first time, when status == .NotDetermined.
Issue seems to be with the Permission/callback lifetime. A workaround is to hold on to the perm variable, by making it a member:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let perm = Permission.Notifications(categories: nil)
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
window = UIWindow(frame: UIScreen.mainScreen().bounds)
if let win = self.window {
let tabs = UITabBarController()
tabs.viewControllers = [MyVC()]
win.rootViewController = tabs
win.makeKeyAndVisible()
}
perm.request { (status) in
print("push callback with status: \(status)")
}
Thanks for letting me know about permission/UIApplicationDelegate relationship, perusing the source should have made it clear. May be an example in the README could help clarify that ? Something along:
let perm = Permission.Notifications(categories: nil)
perm.request { (status) in
print("Received Notifications permission: \(status)")
// Note: following call will be made only if the application has successfully registered for user notifications with registerUserNotificationSettings:, or if it is enabled for Background App Refresh.
UIApplication.sharedApplication().registerForRemoteNotifications()
}
Hmmm strange. I'm already holding the Notifications
permission in the notifications
internal var (see here and here) and it worked just fine (for me at least). I'll store it in a static var
again... Btw you might want to read #13
I don't think it's necessary to add a note in the README as registering for local/remote notifications and allowing notifications (this lib's purpose) are quite distinct:
If you want your app’s remote notifications to display alerts, play sounds, or perform other user-facing actions, you must call the registerUserNotificationSettings: method to request the types of notifications you want to use. If you do not call that method, the system delivers all remote notifications to your app silently. source
I'm gonna ping you when for the static var
stuff 😄
Thanks for the issue!
Hi @DimDL,
I just push the v1.5
and the Notifications
permission is now retained as a static var
. It will hopefully solve your issue (that I didn't manage to reproduce btw). Let me know if you find the time!
Also I added additional granularity for the notification types:
let notifications: Permission = .Notifications
// the types are [.Badge, .Sound, .Alert] and the categories are nil
let notifications: Permission = .Notifications(types: [.Badge], categories: categories)
// the type is [.Badge] and the categories are nil
let notifications: Permission = .Notifications(types: [.Badge, .Alert])
// the types are [.Badge, .Alert] and the categories are nil
let notifications: Permission = .Notifications(categories: ...)
// ...
Hello !
With Permission 1.4, Notification callback is not called. Neither the Permission callback, nor the UIApplicationDelegate one.
To reproduce, put this in your appDidFinishLaunching :
and this: