2017-10-12 21 views
0

Xamarin.Formsプロジェクトでローカル通知を実装するためにXam.Plugins.Notifierパッケージを使用しています。Xam.Plugins.NotifierがIOS 11で動作しない

ここはPCLプロジェクトで書いたコードです。 CrossLocalNotifications.Current.Show( "タイトル"、 "説明");

Androidではうまくいきますが、IOSでは動作しません。 より低いIOS SDKで動作するかどうかわかりません。 とにかくそれはここでIOS 11

上では動作しません私はAppDelegate.cs

  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) => { }); 
      } 
      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); 
      } 

を追加したコードがある誰が私はそれを修正するのに役立つことはできますか? このパッケージをIOS上で動作させたいです。

ありがとうございました。

答えて

0

どのシナリオが機能しませんか?アクティブまたはバックグラウンド?

それがアクティブであるとき、あなたはデリゲートを扱うことを忘れて動作しない場合(サブクラスUNUserNotificationCenterDelegate

以下のようにコードを変更します。

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(); 
} 

は、サブクラスUserNotificationCenterDelegate

を作成します。
public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate 
{ 
    public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler) 
    { 
     // Tell system to display the notification anyway or use 
     // `None` to say we have handled the display locally. 
     completionHandler(UNNotificationPresentationOptions.Alert); 
    } 
} 
+0

ご返信ありがとうございます、私はすでにそれを自分で処理しています。バックグラウンドで動作しない場合は、何を追加する必要がありますか。 –

+0

@ Passionate.Cあなたが提供したコードはバックグラウンドで動作するはずです。 –

関連する問題