0

I've been trying to implement the remote push notification for my app but i can't make it to work, i'm fairly new with this and right now i have this code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UIApplication sharedApplication] registerForRemoteNotifications];
        return YES;
}

for some reason it doesn't request permission for the app to send the push notifications

i already did all the provisional profiles stuff with the certs

any ideas on what can i do?

Cesar Mtz
  • 322
  • 2
  • 13

1 Answers1

0

You need to register the notification types you would like to register for as well:

    UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];

More details here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW2

EDIT If you need iOS 7 compatibility as well, do something like this:

if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) {
    UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
mofojed
  • 1,342
  • 9
  • 11
  • this worked thank, just one more question why is it that it goes straight to the didFailToRegisterForRemoteNotificationsWithError method if i already accepted to send me push notifications? – Cesar Mtz Aug 10 '15 at 01:04
  • Not sure, print out the error for more info: `NSLog(@"Error in registration. Error: %@", error);` – mofojed Aug 10 '15 at 01:07
  • Error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x17026cd40 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application} this is the error that throws – Cesar Mtz Aug 10 '15 at 01:12
  • Sounds like your provisioning profiles aren't updated with the proper push notifications. Set that up in the provisioning profile, make sure the app IDs match, and refresh your provisioning profiles in xcode: http://stackoverflow.com/questions/27324020/no-valid-aps-environment-entitlement-string-found-for-application-on-app-store – mofojed Aug 10 '15 at 01:20