Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push Notifications #6

Closed
cannyboy opened this issue May 7, 2014 · 3 comments
Closed

Push Notifications #6

cannyboy opened this issue May 7, 2014 · 3 comments

Comments

@cannyboy
Copy link

cannyboy commented May 7, 2014

I'm trying to get my head around the push notification part of JLPermissions.

From what I can see [[JLPermissions sharedInstance] notificationsAuthorized] will return NO if my app has notifications enabled in a previous version, which didn't use JLPermissions.

MyApp 1.1 (NO JLPermissions)
(user agrees to permissions)
MyApp 1.2 (WITH JLPermissions)
(JLPermissions assumes user has not agreed)

Should I also check the systems's push notification status ( using this answer on stack overflow http://stackoverflow.com/a/9898632/121646 ) before attempting with either of the authorizeNotifications methods?

@jlaws
Copy link
Owner

jlaws commented May 7, 2014

Unfortunately Apple does not provide a way to tell the difference between permission asked and denied vs permission never asked. You will see that explained in the comment below the post you linked:

"My answer may not directly answer "how to determine if app is in Notification Center", but it does offer a way to check whether or not the user will receive notifications for your app"

Thats why I designed the library to keep track of the deviceID and if it you previously asked and were denied. If you previously obtained permission outside of the library, you can call

  • (void)notificationResult:(NSData *)deviceToken error:(NSError *)error;

With the deviceID you previously obtained, or set the deviceToken to nil and pass in an Error if the user denied permission.

Personally, I ask the user again because the only reason it is not set is 1) they haven't set it yet (and have never seen the dialog) or 2) they denied access, in which case I display a dialog that tells them how to enable it in the notification center by calling this method

  • (void)displayNotificationsErrorDialog;

Hope this helps you decide what to do. Feel free contact Apple about their lacking API.

@jlaws jlaws closed this as completed May 7, 2014
@cannyboy
Copy link
Author

cannyboy commented May 7, 2014

OK, I'll just write out what I'll try to do. Maybe it will help someone else who has a similar issue.

In the current version of the app I ask for push permissions on application:didFinishLaunchingWithOptions: .. which is not good, since it is before they have even logged in.

I store my deviceToken, (if received in didRegisterForRemoteNotificationsWithDeviceToken), as (hex) NSString in NSUserDefaults, using the key “userDefaultDeviceID”. If I don’t get one, or it hasn’t been set, then this userDefaultDeviceToken is returned as @“”

So, to use JLPermissions in the next version, I will ask for push permissions in the appropriate place (after login), like this

if ((userDefaultDeviceToken == nil || [userDefaultDeviceToken isEqualToString:@“”]) && ![[JLPermissions sharedInstance] notificationsAuthorized]) 
// user has no push notifications set
{ 
    [[JLPermissions sharedInstance] authorizeNotifications:^(NSString *deviceID, NSError *error) {

        // show error, possibly as third alert..
        if (![[JLPermissions sharedInstance] notificationsAuthorized]) [[JLPermissions sharedInstance] displayNotificationsErrorDialog]

    }];
} 
else 
{
   // user has notification on, but it is not set in JLPermissions
   if (![[JLPermissions sharedInstance] notificationsAuthorized]) 
   { 
     NSData *deviceTokenData = [self convertToDataFromHexString:userDefaultDeviceToken];
     [[JLPermissions sharedInstance] notificationResult:deviceTokenData  error:nil];
   }
}

@cannyboy
Copy link
Author

"Apple does not provide a way to tell the difference between permission asked and denied vs permission never asked"

Is this still the case on iOS 8? I think there is now a isRegisteredForRemoteNotifications method.

http://stackoverflow.com/a/25990240/121646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants