registerForRemoteNotifications doesn't work.

Hi, everyone.
I am developing a push notification plugin. I want to register for remote notification and get the token. I used [[UIApplication sharedApplication] registerForRemoteNotifications] and UKismetSystemLibrary::RegisterForRemoteNotifications() function, but ApplicationRegisteredForRemoteNotificationsDelegate and ApplicationFailedToRegisterForRemoteNotificationsDelegate both aren’t triggered.

this is my code.

void FPushNotification::StartupModule()
{
	UE_LOG(LogPushNotification, Log, TEXT("%s"), *FString(__FUNCTION__)); // It's triggered.
#if PLATFORM_IOS

    FCoreDelegates::ApplicationRegisteredForRemoteNotificationsDelegate.AddRaw(this, &FPushNotification::ApplicationRegisteredForRemoteNotifications_Handler);
    FCoreDelegates::ApplicationFailedToRegisterForRemoteNotificationsDelegate.AddRaw(this, &FPushNotification::ApplicationFailedToRegisterForRemoteNotifications_Handler);
    FCoreDelegates::ApplicationReceivedRemoteNotificationDelegate.AddRaw(this, &FPushNotification::ApplicationReceivedRemoteNotification_Handler);
    
    UIMutableUserNotificationAction *readAction = [[UIMutableUserNotificationAction alloc] init];
    readAction.identifier = @"READ_IDENTIFIER";
    readAction.title = @"Read";
    readAction.activationMode = UIUserNotificationActivationModeForeground;
    readAction.destructive = NO;
    readAction.authenticationRequired = YES;
    
    UIMutableUserNotificationAction *ignoreAction = [[UIMutableUserNotificationAction alloc] init];
    ignoreAction.identifier = @"IGNORE_IDENTIFIER";
    ignoreAction.title = @"Ignore";
    ignoreAction.activationMode = UIUserNotificationActivationModeBackground;
    ignoreAction.destructive = NO;
    ignoreAction.authenticationRequired = NO;
    
    UIMutableUserNotificationAction *deleteAction = [[UIMutableUserNotificationAction alloc] init];
    deleteAction.identifier = @"DELETE_IDENTIFIER";
    deleteAction.title = @"Delete";
    deleteAction.activationMode = UIUserNotificationActivationModeForeground;
    deleteAction.destructive = YES;
    deleteAction.authenticationRequired = YES;
    
    UIMutableUserNotificationCategory *messageCategory = [[UIMutableUserNotificationCategory alloc] init];
    messageCategory.identifier = @"MESSAGE_CATEGORY";
    [messageCategory setActions:@[readAction, ignoreAction, deleteAction] forContext:UIUserNotificationActionContextDefault];
    [messageCategory setActions:@[readAction, deleteAction] forContext:UIUserNotificationActionContextMinimal];
    
    NSSet *categories = [NSSet setWithObject:messageCategory];
    
    UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
    UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
    
    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];

    UKismetSystemLibrary::RegisterForRemoteNotifications();
#endif
}

void FPushNotification::ApplicationRegisteredForRemoteNotifications_Handler(TArray<uint8> Token)
{
#if PLATFORM_IOS
    NSData* TokenData = [NSData dataWithBytes : Token.GetData() length : Token.Num()];
    NSLog(@"deviceToken: %@", TokenData);
    UE_LOG(LogPushNotification, Log, TEXT("%s"), *FString(__FUNCTION__));
#endif
}


void FPushNotification::ApplicationFailedToRegisterForRemoteNotifications_Handler(FString error)
{
#if PLATFORM_IOS
    UE_LOG(LogPushNotification, Log, TEXT("%s error:%s"), *FString(__FUNCTION__), *error);
#endif
}

I add plist data at ProjectSetting >> iOS >> Extra Plist Data >> Additional Plist Data.

<key>UIBackgroundModes</key><array><string>remote-notification</string></array>

By the way, can I add plist data like android use _APL.xml in the plugin?

Ok, I will upload my project tomorrow, but you still have to get a apple development account.

Hello ,

Thank you for your report. Unfortunately, I currently don’t know much about setting up Push Notifications so this is quite foreign to me. If you would like to upload some sort of reproduction project, that would be helpful. Otherwise, I’ll be trying to learn more about this tomorrow to see if I can get reproduce what you’re seeing and get a bug report in.

I’m sorry for replying you after too long time. I’m very busy recently.
This is my git project. You can try it.
You still have to make your personal apple certificate, I can not give you mine.
Oh, You have to change some project setting of iOS, like BundleIdentifier … etc.

If you can’t make this project running, please tell me as soon as. I would get you some help if I know : (.

I apologize for the delay on this, I’ll be checking on this soon.

Did you try it?

Hello ,

I’ve packaged the project to an iOS device and I am seeing the same behavior, with the push notification delegates not firing (not printing messages to the log when they should). Have you tried doing this from inside the project itself rather than through a plugin to see if this may only be happening with plugins? I’d like to place a bug report in but it would be best to narrow down the affected cases first.

I tried to add RegisterForRemoteNotification to GameMode without plugin, and it still do not works. You can update my project from git, and try again.
I think the engine source code maybe is wrong.

void FIOSPlatformMisc::RegisterForRemoteNotifications()
{
#if !PLATFORM_TVOS
	UIApplication* application = [UIApplication sharedApplication];
	// if ([application respondsToSelector : @selector(registerUserNotifcationSettings:)])
	{
#ifdef __IPHONE_8_0
		UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes : (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil];
		[application registerUserNotificationSettings : settings];
#endif
	}
	else
	{ // I use iPhone5s, it always come here
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
		UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
		[application registerForRemoteNotificationTypes : myTypes]; // It can't run into here. So, it always don't call registerForRemoteNotificationTypes and trigger FCoreDelegates::ApplicationRegisteredForRemoteNotificationsDelegate.
#endif
	}
#endif
}

I tried to call [application registerUserNotificationSettings : settings];, [application registerForRemoteNotifications]; or [application registerForRemoteNotificationTypes : myTypes];, but FCoreDelegates::ApplicationRegisteredForRemoteNotificationsDelegate isn’t triggered.

I think it obviously is a bug. Please try it again and tell me your result. I want to make sure we have same result.

I tried many times. I found didRegisterUserNotificationSettings is fired, when I call [application registerUserNotificationSettings : settings];.

I still don’t know why FCoreDelegates::ApplicationRegisteredForRemoteNotificationsDelegate isn’t triggered. : (

I’m getting the same results but I’m not sure if this is a bug if we have no control scenario where it is working, as it may not be implemented correctly. I’ll look into this and give back to you when I find out more.

Do you know how to add “push notification” to .entitlements file?
Maybe we have to add

<plist version="1.0">
<dict>
	<key>aps-environment</key>
	<string>development</string>
</dict>
</plist>

to .entitlements file, they mean turn on PushNotification of Capabilities.(I think the Capabilities of XCode is for MacOS not iOS. So I add Additional Plist Data in ProjectSetting.)
But, I can’t find where to add something to Entitlements. Do you know this? Or can you ask other people in the iOS department?

Hello . I apologize for the delay on this, as we never resolved this but are you still experiencing this issue in the latest version of the editor?

Have the same issue in 4.23

Hello, is there any update on this???