FireBase iOS推送通知不起作用 - Mobivm& Libgdx

时间:2018-03-30 08:24:28

标签: ios firebase push-notification libgdx robovm

我在Libgdx开发了一款游戏。 我在Android中添加了Firebase推送通知服务,效果很好。 但是当谈到iOS时,它并不起作用。当我在我的iphone上打开应用程序时,它要求我允许推送通知服务,它会创建令牌,但是当我从firebase控制台发送消息时,消息不会出现。有什么问题?

相关链接:

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

我的代码:

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();
    }
}

0 个答案:

没有答案