rdelrosario / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
179 stars 161 forks source link

IOS Push. #117

Open RodolfoMota opened 7 years ago

RodolfoMota commented 7 years ago

Hey, im using xamarin-plugins with firebase. I'm not getting the push.

That is what I have.

`[Register("AppDelegate")] public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate { // // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. //

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
        CachedImageRenderer.Init();
        LoadApplication(new App());
        CarouselViewRenderer.Init();
        //Consider inizializing before application initialization, if using any CrossPushNotification method during application initialization.
        CrossPushNotification.Initialize<CrossPushNotificationListener>();
        //...

        UIUserNotificationType userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
        UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
        UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

        return base.FinishedLaunching(app, options);
    }

    const string TAG = "PushNotification-APN";

    public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
    {

        if (CrossPushNotification.Current is IPushNotificationHandler)
        {
            ((IPushNotificationHandler)CrossPushNotification.Current).OnErrorReceived(error);

        }

    }

    public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
    {
        if (CrossPushNotification.Current is IPushNotificationHandler)
        {
            ((IPushNotificationHandler)CrossPushNotification.Current).OnRegisteredSuccess(deviceToken);

        }

    }

    public override void DidRegisterUserNotificationSettings(UIApplication application, UIUserNotificationSettings notificationSettings)
    {
        application.RegisterForRemoteNotifications();
    }

    //Uncomment if using remote background notifications. To support this background mode, enable the Remote notifications option from the Background modes section of iOS project properties. (You can also enable this support by including the UIBackgroundModes key with the remote-notification value in your app�s Info.plist file.)
    public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        if (CrossPushNotification.Current is IPushNotificationHandler) 
        {
            ((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);

        }
    }

    public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
    {

        if (CrossPushNotification.Current is IPushNotificationHandler)
        {
            ((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(userInfo);

        }
    }

}`

Console 2017-04-06 17:22:23.828 Rest.iOS[2555:2041400] CrossPushNotification - Token: b8703e9e4e5084270d1f887a4e8d1ff08c245f35531337f8e414d688d [0:] Push Notification - Device Registered - Token : b8703e9e4e5084270d1f887a4e8d1ff08c245f35531337f8e414d688d

Lkhagvajargal commented 7 years ago

Is anyone know something about this problem? I have same problem.

carvah commented 7 years ago

I have the same problem... any fix for this? I have every permissions enabled.

ghost commented 7 years ago

Did you use the Firebase library to convert the APNS token to a Firebase token? You cannot use the APNS token (in your example, b8703e9e4e5084270d1f887a4e8d1ff08c245f35531337f8e414d688d) as-in from your server code.

AmaralDR commented 7 years ago

@bontibon Do you have any examples of how to convert this TOKEN?

ghost commented 7 years ago

@AmaralDR I don't, as I decided to implemented separate GCM and APNS logic on my server.