V
V
Vladislav Pavlenko2016-08-16 13:44:21
Objective-C
Vladislav Pavlenko, 2016-08-16 13:44:21

Can't get deviceToken (didRegisterForRemoteNotificationsWithDeviceToken)?

Hello! Help me please!
I'm trying to make push notifications. You need to send a login, a token and a device token to the server.
In the didRegisterUserNotificationSettings method I am trying to save the deviceToken. But I get into didFailToRegisterForRemoteNotificationsWithError.
Code attached

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
        
        ;
    } else {
        
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert |
                                                                               UIRemoteNotificationTypeBadge |
                                                                               UIRemoteNotificationTypeSound)];
    }
    
    return YES;
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    NSLog(@"token - %@", token);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"Failed to get token, error: %@", [error localizedDescription]);
}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
J
jazzz13, 2016-08-20
@pavlenkovs

1) what does [error localizedDescription] output?
2) is an attempt to get a token done on a real device or a simulator?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question