Git Product home page Git Product logo

Comments (14)

edmckee avatar edmckee commented on June 7, 2024 1

Well, I thought this made sense but i'm calling CrossPushNotification.Current.RegisterForPushNotifications() in the new version and I am receiving notifications, but they don't go to the OnNotificationOpened. Is there something in the Initialize(options,true) besides the user permissions that might impact the OnNotificationOpened not being called? I'll still try out the autoregister

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

iOS by default receive the notification only when tapped. If you want to receive it when arrive should send content-available: 1

More info here:

https://developer.xamarin.com/guides/ios/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/updating_an_application_in_the_background/

from pushnotificationplugin.

edmckee avatar edmckee commented on June 7, 2024

The issue is the when I click the notification it opens the app and the OnNotificationReceived event is called, but not the OnNotificationOpened. This works on Android but not on iOS, and used to work on iOS

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

How are tou initializing the plugin on iOS?

from pushnotificationplugin.

edmckee avatar edmckee commented on June 7, 2024

Here's the main area
LoadApplication(new App()); PushNotificationManager.Initialize(options, false); return base.FinishedLaunching(app, options);

from pushnotificationplugin.

edmckee avatar edmckee commented on June 7, 2024

And then this.
` public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
{
PushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
}

    public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
    {
        PushNotificationManager.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)
    {
        PushNotificationManager.DidReceiveMessage(userInfo);
    }`

from pushnotificationplugin.

edmckee avatar edmckee commented on June 7, 2024

I did revert back to version 1.2.6 and the OnNotificationOpened worked with no application changes except the new CrossPushNotification.Current.RegisterForPushNotifications() was commented out.
I also tried 1.2.8-beta and that didn't work either. So either I need to do something different with 1.3.0 or something isn't quite right.
Thanks again

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

Ok the problem seems to be here you are setting autoRegister to false when initializing.

PushNotificationManager.Initialize(NSDictionary options,bool autoRegistration) : Default method to initialize plugin without supporting any user notification categories. Auto registers for push notifications if second parameter is true.

If you do that you need to call CrossPushNotification.Current.RegisterForPushNotifications() at some point. Because is where it gets the delegate set.

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024
PushNotificationManager.Initialize(options,true)

If auto register true will call CrossPushNotification.Current.RegisterForPushNotifications() internally. Which is where delegate is set.

PushNotificationManager.Initialize(options,false)

If auto register false won't call CrossPushNotification.Current.RegisterForPushNotifications(). Which is where delegate is set , so you need to call CrossPushNotification.Current.RegisterForPushNotifications() manually at the point you desire permissions are asked.

from pushnotificationplugin.

edmckee avatar edmckee commented on June 7, 2024

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

mmm shouldn't impact unless you assign UNUserNotificationCenter.Current.Delegate after that call which is assigned internally. Here is what it does internally:

public async Task RegisterForPushNotifications()
        {
            TaskCompletionSource<bool> permisionTask = new TaskCompletionSource<bool>();

            // Register your app for remote notifications.
            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                // iOS 10 or later
                var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;


                // For iOS 10 display notification (sent via APNS)
                UNUserNotificationCenter.Current.Delegate = CrossPushNotification.Current as IUNUserNotificationCenterDelegate;

                UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
                {
                    if (error != null)
                           _onNotificationError?.Invoke(CrossPushNotification.Current, new PushNotificationErrorEventArgs(PushNotificationErrorType.PermissionDenied, error.Description));
                    else if (!granted)
                           _onNotificationError?.Invoke(CrossPushNotification.Current, new PushNotificationErrorEventArgs( PushNotificationErrorType.PermissionDenied,"Push notification permission not granted"));


                    permisionTask.SetResult(granted);
                });



            }
            else
            {
                // iOS 9 or before
                var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                permisionTask.SetResult(true);
            }


            var permissonGranted = await permisionTask.Task;

            if (permissonGranted)
            {
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }
        }

And when you initialize it basically just calls this method if true

 public static async Task Initialize(NSDictionary options, bool autoRegistration = true)
        {
            CrossPushNotification.Current.NotificationHandler = CrossPushNotification.Current.NotificationHandler ?? new DefaultPushNotificationHandler();

            if (autoRegistration)
            {
                await CrossPushNotification.Current.RegisterForPushNotifications();
            }

        }

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

Are you still having this issue?

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

Let me know if still having this issue.

from pushnotificationplugin.

rdelrosario avatar rdelrosario commented on June 7, 2024

Will close this for now because can't reproduce, if still happening for you feel free to reopen it.

from pushnotificationplugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.