rdelrosario / xamarin-plugins

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

Init not working under iOS #17

Closed ThomasKIT closed 7 years ago

ThomasKIT commented 8 years ago

I am successfully using the plugin on Android, but with iOS it fails during initilization.

iOS 8.4: Should initialize before use on FinishedLaunching method of AppDelegate class. Example: CrossPushNotification.Initialize()

iOS 7.1: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

Last point of entry before the exceptions occur: CrossPushNotification.Current.Register()

This is my AppDelegate FinishedLaunching:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();

        CrossPushNotification.Initialize<CrossPushNotificationListener>();

        InitXLabsServices();
        ImageCircleRenderer.Init();
        LoadApplication(new KinsmenApp());

        return base.FinishedLaunching(app, options);
    }

Of course I did set up the Provisioning Profile and Push Notification Permission at the Developer Center.

How can I get more information about where it actually crashes inside the plugin?

Edit: I took a look at the plugin's source code and after using the following three lines directly it registered successfully, but this way I am not using the Plugin:

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

Could it be possible that the preprocessor directives aren't getting handled properly and therefore the wrong code gets executed?

if IOS

rdelrosario commented 8 years ago

You should initialize the plugin after the LoadApplication call. On Aug 11, 2015 6:41 AM, "ThomasKIT" notifications@github.com wrote:

I am successfully using the plugin on Android, but with iOS it fails during initilization.

iOS 8.4: Should initialize before use on FinishedLaunching method of AppDelegate class. Example: CrossPushNotification.Initialize()

iOS 7.1: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

Last point of entry before the exceptions occur: CrossPushNotification.Current.Register()

This is my AppDelegate FinishedLaunching: public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init();

    CrossPushNotification.Initialize<CrossPushNotificationListener>();

    InitXLabsServices();

    ImageCircleRenderer.Init();

    LoadApplication(new KinsmenApp());

    return base.FinishedLaunching(app, options);
}

Of course I did set up the Provisioning Profile and Push Notification Permission at the Developer Center.

How can I get more information about where it actually crashes inside the plugin?

— Reply to this email directly or view it on GitHub https://github.com/rdelrosario/xamarin-plugins/issues/17.

ThomasKIT commented 8 years ago

That leads to

  UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
rdelrosario commented 8 years ago

Can you send the code where you are calling the register method? On Aug 11, 2015 11:17 AM, "ThomasKIT" notifications@github.com wrote:

This leads to UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

— Reply to this email directly or view it on GitHub https://github.com/rdelrosario/xamarin-plugins/issues/17#issuecomment-129926312 .