プラットフォームプロジェクトにインターフェイスを追加する必要はありません。Android/IOSの両方のプロジェクトにインゴルネージパッケージをインストールするだけです。
IOSに追加する必要があります
// Ask the user for permission to get notifications on iOS 8.0+
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
var settings = UIUserNotificationSettings.GetSettingsForTypes (
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
new NSSet());
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
}
あなたの方法に:AppDelegateで
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
:次に
を共有プロジェクトであなたが呼び出す:
using Plugin.LocalNotifications.Abstractions;
CrossLocalNotifications.Current.Show("You've got mail", "You have 793 unread messages!");
あなたの現在のページであれば、何もする必要はありません.Xamarin Formsはそれを処理します。 Android上でも
、あなたはMainActivityのLaunchModeを設定することにより、あなたのアプリケーション・リニューアルの動作をcontrollことができます。
例:
LaunchMode = Android.Content.PM.LaunchMode.SingleInstance, AlwaysRetainTaskState = true
をAndroid上LauchModes詳細情報は、お読みください:
https://developer.android.com/guide/components/tasks-and-back-stack.html
追加のアクティビティフラグ:
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_SINGLE_TOP
現在のところ、このプラグインはアプリ内で通知を受け取ることを許可していません。 しかし、あなたがこれを行うことができ、プラットフォーム固有の機能
IOSを使用して: https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/ios/remote_notifications_in_ios/
public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
{
MessagingCenter.Send<MainPage> (this, "IOS notification received");
}
を参照してくださいアンドロイド: このプラグインのソースを通して読んだ後、私は発見した、そのyoucanチェックあなたはBroadcastReceを使用しようとすることができ、キーScheduledAlarmHandler.LocalNotificationKeyまた
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
if(bundle.ContainsKey(ScheduledAlarmHandler.LocalNotificationKey)){
//App launched form notification
MessagingCenter.Send<MainPage> (this, "Android notification received");
}
}
するための方法を作成し、あなたの上にバンドル私はクラスです。 https://developer.xamarin.com/api/type/Android.Content.BroadcastReceiver/
ありがとうございます。私はそれを試みました(Notifier.Current.Show( "あなたはメールを持っています"、 "未読メッセージが793件あります!");)。今度はコンソールでパッケージをインストールしようとしましたが、ItemNotFoundExceptionが発生しました。 アイデアは何ですか? – guenes
少し例を編集しましたが、これを試してください – Greensy
ありがとうございました。 CrossLocalNotificationsは機能します。今、私はあなたのツタンカーメンの残りを試してみましょう。 – guenes