Search code examples
iphonexcode4push-notificationapple-push-notifications

enabling notifications


I would like to enable notifications in my iphone app. So, I modify in app ID:

enter image description here

After that, I generate again Development and Distribution Provisioning Profiles and installed in my xcode.

My app is a tabbed based application, the first tab is UITableViewController

I add this lines:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

   return YES;
}

So, I suppose I should have my app in the list of app installed with notifications in my iphone, but it isnt.

Did I miss some step?


Solution

  • Yep. According to this and this you should add the registerForRemoteNotificationTypes method in your didFinishLaunchingWithOptions, which should the look something like this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {    
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    
        return YES;
    }
    

    Depending on which Types you registered your app will appear in the notifications section and you can turn on and off the different types (sound, badge, banner).

    Hope that helps.