EDIT
I'll put this at the top as this seems to possibly be the issue. After registering user settings, I NSLog:
NSLog(@"current notifications : %@", [application currentUserNotificationSettings]);
I receive back:
current notifications : <UIUserNotificationSettings: 0x165844a0; types: (none);>
But as you can see, I am clearly registering the settings to use badge, sound, and alerts.
Also, I guess I should mention that I have turned off notifications in my settings. However, I expect it to call
didFailToRegisterForRemoteNotificationsWithErrorin this case which is where I generate my own phone ID.
-- I take back what I said above. When I delete the app and reinstall it, it turns back on Allow Notifications. --
I know this question is on here a lot, but I just cannot seem to get this working. Here is my dumbed-down code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self registerForNotifications:application];
}
- (void)registerForNotifications:(UIApplication *)application {
// Let the device know we want to receive push notifications
NSLog(@"Registering for Remote Notifications");
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
#ifdef __IPHONE_8_0
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert) categories:nil];
[application registerUserNotificationSettings:settings];
#endif
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
[application registerForRemoteNotificationTypes:myTypes];
}
NSLog(@"Done registering for Remote Notifications");
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
NSLog(@"Did register for remote notification settings");
//register to receive notifications
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
NSLog(@"There was an error?");
//handle the actions
if ([identifier isEqualToString:@"declineAction"]){
}else if ([identifier isEqualToString:@"answerAction"]){
}
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(@"My token is: %@\nMy device token is: %@\nSend Phone ID is: %@", [self loadSettings:@"phone_id"], deviceToken, [self loadSettings:@"send_phone_id"]);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Failed to register for remote notifications");
}
For my NSLog statements, this is all I receive:
2014-11-11 14:57:11.066 eTicket[3144:988203] Registering for Remote Notifications
2014-11-11 14:57:11.083 eTicket[3144:988203] Done registering for Remote Notifications
2014-11-11 14:57:11.148 eTicket[3144:988203] Settings Validated?: NO
2014-11-11 14:57:11.219 eTicket[3144:988203] Did register for remote notification settings
Ignore the "Settings Validated" line. That's just me checking to see if they've successfully logged in already to skip some steps. That part works and doesn't have anything to do with remote notifications.
I'm getting no indication that it registered for notifications successfully or not, or that there is an error. The application does not crash or throw errors. I am lost as to why none of the bottom methods are being hit.
Thanks, James