public void Regist() { if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { // 許可をもらう通知タイプの種類を定義 UNAuthorizationOptions types = UNAuthorizationOptions.Badge | // アイコンバッチ UNAuthorizationOptions.Sound | // サウンド UNAuthorizationOptions.Alert; // テキスト UNUserNotificationCenter.Current.RequestAuthorization(types, (granted, err) => { // Handle approval if (err != null) { System.Diagnostics.Debug.WriteLine(err.LocalizedFailureReason + System.Environment.NewLine + err.LocalizedDescription); } if (granted) { } }); } else //iOS9まで向け // 許可をもらう通知タイプの種類を定義 { UIUserNotificationType types = UIUserNotificationType.Badge | // アイコンバッチ UIUserNotificationType.Sound | // サウンド UIUserNotificationType.Alert; // テキスト // UIUserNotificationSettingsの生成 UIUserNotificationSettings nSettings = UIUserNotificationSettings.GetSettingsForTypes(types, null); // アプリケーションに登録 UIApplication.SharedApplication.RegisterUserNotificationSettings(nSettings); } }
public IOSNotificationService() { // UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { // iOS 10 or later UNAuthorizationOptions authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound; UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => { _hasNotificationsPermission = granted; Console.WriteLine(granted); }); // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.Current.Delegate = new IOSNotificationReceiver(); // For iOS 10 data message (sent via FCM) //Messaging.SharedInstance.RemoteMessageDelegate = this; } else { // iOS 9 or before UIUserNotificationType allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); } }
private async void SetupPushNotifications() { #pragma warning disable XI0003 // Notifies you when using a deprecated, obsolete or unavailable Apple API #pragma warning disable XI0002 // Notifies you from using newer Apple APIs when targeting an older OS version if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { // iOS 10 or later UNAuthorizationOptions authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound; UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => Console.WriteLine(granted)); // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.Current.Delegate = this; // For iOS 10 data message (sent via FCM) Messaging.SharedInstance.Delegate = this; } else { // iOS 9 or before var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); } UIApplication.SharedApplication.RegisterForRemoteNotifications(); var instanceId = await Firebase.InstanceID.InstanceId.SharedInstance.GetIdAsync(); Debug.Print("Instance ID: " + instanceId); #pragma warning restore XI0002 // Notifies you from using newer Apple APIs when targeting an older OS version #pragma warning restore XI0003 // Notifies you when using a deprecated, obsolete or unavailable Apple API }
Task <Tuple <bool, NSError> > RequestUserAccess() { UNAuthorizationOptions options = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge; return(notificationCenter.RequestAuthorizationAsync(options)); }
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { Firebase.Core.App.Configure(); Firebase.Crashlytics.Crashlytics.Configure(); Forms.Init(); ImageCircleRenderer.Init(); _network = App.Container.Resolve <INetwork>(); // iOS 10 or later const UNAuthorizationOptions authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound; UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => { Console.WriteLine(granted); }); UIApplication.SharedApplication.RegisterForRemoteNotifications(); LoadApplication(application: new App()); Firebase.InstanceID.InstanceId.Notifications.ObserveTokenRefresh((sender, e) => { var fcmTokenReload = Messaging.SharedInstance.FcmToken; if (!string.IsNullOrEmpty(fcmTokenReload)) { var isSuccess = Xamarin.Forms.Application.Current.Properties.TryGetValue("fcmTokenAmver", out var fcmTokenObj); if (isSuccess) { Xamarin.Forms.Application.Current.Properties.Remove("fcmTokenAmver"); } Xamarin.Forms.Application.Current.Properties.Add("fcmTokenAmver", fcmTokenReload); LoadFcmAsync(fcmTokenReload); } }); var fcmTokenReload = Messaging.SharedInstance.FcmToken; if (!string.IsNullOrEmpty(fcmTokenReload)) { var isSuccess = Xamarin.Forms.Application.Current.Properties.TryGetValue("fcmTokenAmver", out var fcmTokenObj); if (isSuccess) { Xamarin.Forms.Application.Current.Properties.Remove("fcmTokenAmver"); } Xamarin.Forms.Application.Current.Properties.Add("fcmTokenAmver", fcmTokenReload); LoadFcmAsync(fcmTokenReload); } return(base.FinishedLaunching(app, options)); }
public void Initialize() { if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { UNAuthorizationOptions types = UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Alert; UNUserNotificationCenter.Current.RequestAuthorization(types, (granted, err) => { // Handle approval if (err != null) { System.Diagnostics.Debug.WriteLine(err.LocalizedFailureReason + System.Environment.NewLine + err.LocalizedDescription); } if (granted) { } }); } }