Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token not get picked up on app restart #56

Open
mohammedmsadiq opened this issue Nov 16, 2020 · 0 comments
Open

Token not get picked up on app restart #56

mohammedmsadiq opened this issue Nov 16, 2020 · 0 comments

Comments

@mohammedmsadiq
Copy link

when receiving the notification for the 1st time it works fine but when the app restarts the token is empty and the app crashes see below for screenshots;

Screenshot 2020-11-16 at 23 21 10

my implementation below;

on appdelgete

        UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, true); // <--- copy this instruction

        LoadApplication(new App(new iOSInitializer()));

        AzurePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Sound;
        AzurePushNotificationManager.Initialize(NotificationContstants.ListenConnectionString, NotificationContstants.NotificationHubName, launchOptions, true);
        return base.FinishedLaunching(uiApplication, launchOptions);
    }

    public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
    {
        AzurePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
    }

    public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
    {
        AzurePushNotificationManager.RemoteNotificationRegistrationFailed(error);

    }

    // To receive notifications in foregroung on iOS 9 and below.
    // To receive notifications in background in any iOS version
    public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
    {
        AzurePushNotificationManager.DidReceiveMessage(userInfo);
    }

on the app.xaml.cs file my implementation; onstart();

        // Handle when your app starts
        CrossAzurePushNotification.Current.OnTokenRefresh += (s, p) =>
        {
            Debug.WriteLine($"PushNotification TOOKEN REC: {p.Token}");
        };

        Debug.WriteLine($"PushNotification TOOKEN: {CrossAzurePushNotification.Current.Token}");

        CrossAzurePushNotification.Current.OnNotificationOpened += (s, p) =>
        {
            //System.Diagnostics.Debug.WriteLine(p.Identifier);

            Debug.WriteLine("Opened");
            foreach (var data in p.Data)
            {
                Debug.WriteLine($"{data.Key} : {data.Value}");
            }

            if (p.Data["aps.type"].ToString() == "Ecards")
            {
                Settings.WasLaunchedFromPush = true;
                Preferences.Set("IsFromHomePage", true);
                var instanceID = p.Data["aps.parameters"];
                Debug.WriteLine(instanceID);

                var navigationParams = new NavigationParameters();
                navigationParams.Add("questionInstanceID", instanceID);
                NavigationService.NavigateAsync("ECardQuestionPage", navigationParams, true, false);

            }
            else
            {
                Settings.WasLaunchedFromPush = true;
            }
        };

        CrossAzurePushNotification.Current.OnNotificationDeleted += (s, p) =>
        {
            Debug.WriteLine("Dismissed");
        };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant