x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.13
Tags:
more ▼

asked Nov 15 '16 at 03:56 AM in Bug Reports

avatar image

ALangHung
96 4 9 12

avatar image Matthew J Nov 17 '16 at 07:21 PM

Hello ALangHung,

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.

avatar image ALangHung Nov 17 '16 at 07:50 PM

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

avatar image ALangHung Dec 01 '16 at 08:01 AM

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 : (.

avatar image Matthew J Dec 08 '16 at 04:20 PM

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

avatar image ALangHung Dec 29 '16 at 05:42 PM

Did you try it?

avatar image Matthew J Jan 05 '17 at 03:42 PM

Hello ALangHung,

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.

avatar image ALangHung Jan 06 '17 at 03:28 AM

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.

avatar image Matthew J Jan 06 '17 at 03:04 PM

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.

avatar image ALangHung Jan 06 '17 at 04:23 PM

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?

avatar image ALangHung Jan 06 '17 at 02:23 PM

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. : (

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello ALangHung. 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?

more ▼

answered Aug 30 '17 at 01:47 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question