0

I do not know how to replace "method" with the following app delegate method.

viewcontroller

[(AppDelegate *)[[UIApplication sharedApplication] delegate] method];

appdelegate

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    TUPushHelper * helper = [[TUPushHelper alloc] initWithTokenData:devToken];
    [helper registerDevice];
}

1 Answer 1

2

You do not need to call it programmatically. The delegate receives this message after the registerForRemoteNotificationTypes: method of UIApplication is invoked and there is no error in the registration process. didFailToRegisterForRemoteNotificationsWithError: will be called otherwise.

To register your device for remote push notifications you have to do this:

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

Edit: Check Apple Guide for APNS here

also check out this tutorial

2
  • Does the app have to be launched in order for it register device? I am trying to setup a switch statement that unregister devices and register devices instantly.
    – Joe Aikman
    Mar 26, 2013 at 15:46
  • This will be done once on your app first launch. User will be prompted about Push Notifications and he will allow \ deny them. Also you can't unregister remote notifications programmatically, because it makes no sense to do so. Registering doesn't mean you actually get notifications. Mar 26, 2013 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.