//Remote notification support private void RegisterForNotifications(UIApplication application) { if (application.IsRegisteredForRemoteNotifications) { var types = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(types, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); } else { application.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.Badge | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound); } UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.Delegate = this; center.RequestAuthorization(UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Alert, (success, error) => { if (error != null) { Debug.WriteLine(String.Format("Error registering for UserNotifications {0}", error)); } else { Debug.WriteLine("Registered for UserNotifications"); } }); }
private void settingsForLocalNotifications() { UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.RequestAuthorization(UNAuthorizationOptions.Alert, (bool success, NSError error) => { // Set the Delegate regardless of success; users can modify their notification // preferences at any time in the Settings app. center.Delegate = new NotificationCenterDelegate(); }); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.RequestAuthorization(UNAuthorizationOptions.Alert, (bool success, NSError error) => { // Set the Delegate regardless of success; users can modify their notification // preferences at any time in the Settings app. center.Delegate = this; }); return(true); }
/// <summary> /// 注册apns远程推送 /// </summary> /// <param name="launchOptions"></param> protected void RegistLogin(NSDictionary launchOptions) { string systemVersion = UIDevice.CurrentDevice.SystemVersion.Split('.')[0]; Console.WriteLine("System Version: " + UIDevice.CurrentDevice.SystemVersion); //iOS10以上的注册方式 if (float.Parse(systemVersion) >= 10.0) { UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.RequestAuthorization((UNAuthorizationOptions.CarPlay | UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge), (bool arg1, NSError arg2) => { if (arg1) { Console.WriteLine("ios 10 request notification success"); } else { Console.WriteLine("IOS 10 request notification failed"); } }); } //iOS8以上的注册方式 else if (float.Parse(systemVersion) >= 8.0) { UIUserNotificationSettings notiSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(notiSettings); } //iOS8以下的注册方式,这里我们最低版本是7.0以上 else { UIRemoteNotificationType myTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound | UIRemoteNotificationType.Badge; UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(myTypes); } UIApplication.SharedApplication.RegisterForRemoteNotifications(); if (launchOptions != null) { NSDictionary remoteNotification = (NSDictionary)(launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey)); if (remoteNotification != null) { Console.WriteLine(remoteNotification); //这里是跳转页面用的 //this.goToMessageViewControllerWith(remoteNotification); } } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // Request authorization to send notifications UNUserNotificationCenter center = UNUserNotificationCenter.Current; var options = UNAuthorizationOptions.ProvidesAppNotificationSettings | UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Provisional; center.RequestAuthorization(options, (bool success, NSError error) => { center.Delegate = this; var rotateTwentyDegreesAction = UNNotificationAction.FromIdentifier("rotate-twenty-degrees-action", "Rotate 20°", UNNotificationActionOptions.None); var redCategory = UNNotificationCategory.FromIdentifier( "red-category", new UNNotificationAction[] { rotateTwentyDegreesAction }, new string[] { }, UNNotificationCategoryOptions.CustomDismissAction ); var greenCategory = UNNotificationCategory.FromIdentifier( "green-category", new UNNotificationAction[] { rotateTwentyDegreesAction }, new string[] { }, UNNotificationCategoryOptions.CustomDismissAction ); var set = new NSSet <UNNotificationCategory>(redCategory, greenCategory); center.SetNotificationCategories(set); }); // Initialize granular notification settings on first run bool initializedNotificationSettings = NSUserDefaults.StandardUserDefaults.BoolForKey(InitializedNotificationSettingsKey); if (!initializedNotificationSettings) { NSUserDefaults.StandardUserDefaults.SetBool(true, ManageNotificationsViewController.RedNotificationsEnabledKey); NSUserDefaults.StandardUserDefaults.SetBool(true, ManageNotificationsViewController.GreenNotificationsEnabledKey); NSUserDefaults.StandardUserDefaults.SetBool(true, InitializedNotificationSettingsKey); } return(true); }
// // 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) { #if DEBUG // Make sure we can debug against a localhost with invalid SSL certificate ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; #endif global::Xamarin.Forms.Forms.Init(); LoadApplication(new App()); UNUserNotificationCenter center = UNUserNotificationCenter.Current; var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Provisional; center.RequestAuthorization(authOptions, (bool success, NSError error) => { if (!success) { throw new Exception("No access..."); } }); return(base.FinishedLaunching(app, options)); }
public void CheckNotificationPermission() { if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { UNUserNotificationCenter notificationCenter = UNUserNotificationCenter.Current; notificationCenter.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (approved, err) => { if (approved) { App.AppLogger.D("User approved the notification center access"); } else { App.AppLogger.D("User doesn't approved the notification center access"); } }); notificationCenter.Delegate = new NotificationDelegate(); } else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings); } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { global::Xamarin.Forms.Forms.Init(); LoadApplication(new App(new iOSInitializer())); if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound, (bool arg1, NSError arg2) => {}); center.Delegate = new NotificationDelegate(); } else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Sound, new NSSet()); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); } //instantiate beacon tracker _beaconMonitor = new BeaconMonitor(); return(base.FinishedLaunching(application, launchOptions)); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // Override point for customization after application launch. // If not required for your application you can safely delete this method Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.BackgroundColor = UIColor.GroupTableViewBackgroundColor; #region 极光推送注册 MsgBoxHelper.Initialize(this); if (float.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) >= 10.0) { UNUserNotificationCenter center = UNUserNotificationCenter.Current; center.RequestAuthorization((UNAuthorizationOptions.CarPlay | UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge), (bool arg1, NSError arg2) => { if (arg1) { Console.WriteLine("ios 10 request notification success"); } else { Console.WriteLine("IOS 10 request notification failed"); } }); } else if (float.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) >= 8.0) { UIUserNotificationSettings notiSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(notiSettings); } else { UIRemoteNotificationType myTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound | UIRemoteNotificationType.Badge; UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(myTypes); } /* * JPUSHService.SetupWithOption(launchOptions, "466439cd8279089311ead639", "Publish channel", false); * 将上面代码中的应用程序码换成你在极光服务器上注册的应用码,通过极光服务器发送推送消息,在真机上测试即可收到。 */ JPUSHService.SetupWithOption(launchOptions, "466439cd8279089311ead639", "Publish channel", false); JPUSHService.SetDebugMode(); UIApplication.SharedApplication.RegisterForRemoteNotifications(); //JPUSHService.RegistrationIDCompletionHandler((int arg1, NSString arg2) => //{ // if (arg1 == 0) // Console.WriteLine(arg2); //}); if (launchOptions != null) { NSDictionary remoteNotification = (NSDictionary)(launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey)); if (remoteNotification != null) { Console.WriteLine(remoteNotification); this.goToMessageViewControllerWith(remoteNotification); } } #endregion Window.RootViewController = new UINavigationController(new ViewController()); // make the window visible Window.MakeKeyAndVisible(); return(true); }