4

I developed a game in Libgdx. I added Firebase push notification service in Android, it works well. But when it comes to iOS, it doesn't work. When i open the app on my iphone, it asks me to allow push notificaton service, it creates the token, but when i send the message from firebase console, the message does not come. What is the problem?

Related Links:

1) https://www.squins.com/knowledge/adding-firebase-analytics-to-a-robovm-ios-app/

2) https://github.com/MobiVM/robovm-robopods/tree/master/firebase/ios-messaging

My Code:

import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.uikit.UIApplication;

import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration;

import org.robovm.apple.uikit.UIUserNotificationSettings;
import org.robovm.apple.uikit.UIUserNotificationType;
import org.robovm.apple.usernotifications.UNAuthorizationOptions;
import org.robovm.apple.usernotifications.UNNotification;
import org.robovm.apple.usernotifications.UNNotificationPresentationOptions;
import org.robovm.apple.usernotifications.UNNotificationResponse;
import org.robovm.apple.usernotifications.UNUserNotificationCenter;
import org.robovm.apple.usernotifications.UNUserNotificationCenterDelegate;
import org.robovm.objc.block.VoidBlock1;
import org.robovm.pods.firebase.core.FIRApp;
import org.robovm.pods.firebase.messaging.FIRMessaging;
import org.robovm.pods.firebase.messaging.FIRMessagingDelegate;
import org.robovm.pods.firebase.messaging.FIRMessagingRemoteMessage;

public class IOSLauncher extends IOSApplication.Delegate implements UNUserNotificationCenterDelegate, FIRMessagingDelegate{
    @Override
    protected IOSApplication createApplication() {
        FIRApp.configure();
        if (UNUserNotificationCenter.class != null){
            UNUserNotificationCenter.currentNotificationCenter().setDelegate(this);
            FIRMessaging.messaging().setDelegate(this);

            UNAuthorizationOptions authOptions = UNAuthorizationOptions.with(UNAuthorizationOptions.Alert, UNAuthorizationOptions.Sound, UNAuthorizationOptions.Badge);

            UNUserNotificationCenter.currentNotificationCenter().requestAuthorization(authOptions, null);

        } else{
            UIUserNotificationType allNotificationTypes = UIUserNotificationType.with(UIUserNotificationType.Alert, UIUserNotificationType.Sound, UIUserNotificationType.Badge);
            UIUserNotificationSettings settings = new UIUserNotificationSettings(allNotificationTypes, null);
            UIApplication.getSharedApplication().registerUserNotificationSettings(settings);
        }

        UIApplication.getSharedApplication().registerForRemoteNotifications();

        IOSApplicationConfiguration config = new IOSApplicationConfiguration();
        return new IOSApplication(new MyGame(), config);
    }


    public void applicationReceivedRemoteMessage(FIRMessagingRemoteMessage a){

    }

    public void willPresentNotification(UNUserNotificationCenter a, UNNotification b, VoidBlock1<UNNotificationPresentationOptions> c){

    }

    public void didReceiveRegistrationToken(String b){

    }

    public void didRefreshRegistrationToken(FIRMessaging a, String b){

    }

    public void didReceiveMessage(FIRMessaging a, FIRMessagingRemoteMessage b){

    }

    public void didReceiveNotificationMessage(UNUserNotificationCenter a, UNNotificationResponse b, Runnable c){

    }

    public void didReceiveNotificationResponse(UNUserNotificationCenter a, UNNotificationResponse b, Runnable c){

    }

    public static void main(String[] argv) {
        NSAutoreleasePool pool = new NSAutoreleasePool();
        UIApplication.main(argv, null, IOSLauncher.class);
        pool.close();
    }
}
Yazilim Rd
  • 71
  • 1

0 Answers0