You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
2.2 KiB
52 lines
2.2 KiB
using Foundation;
|
|
using UIKit;
|
|
using UserNotifications;
|
|
|
|
namespace Demo.iOS
|
|
{
|
|
// The UIApplicationDelegate for the application. This class is responsible for launching the
|
|
// User Interface of the application, as well as listening (and optionally responding) to
|
|
// application events from iOS.
|
|
[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)
|
|
{
|
|
this.Notification();
|
|
global::Xamarin.Forms.Forms.Init();
|
|
LoadApplication(new App());
|
|
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
|
|
return base.FinishedLaunching(app, options);
|
|
}
|
|
|
|
public void Notification()
|
|
{
|
|
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
|
|
{
|
|
// Ask the user for permission to get notifications on iOS 10.0+
|
|
UNUserNotificationCenter.Current.RequestAuthorization(
|
|
UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
|
|
(approved, error) => { });
|
|
|
|
// Watch for notifications while app is active
|
|
UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
|
|
}
|
|
else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
|
|
{
|
|
// Ask the user for permission to get notifications on iOS 8.0+
|
|
var settings = UIUserNotificationSettings.GetSettingsForTypes(
|
|
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
|
|
new NSSet());
|
|
|
|
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
|
|
}
|
|
}
|
|
}
|
|
} |