Xamarin.Forms上的示例代码 https:/documentation.onesignal.comdocsxamarin-sdk-setup。 (2.1A节)似乎有点过时了。我不得不改变了几个包的对象,比如 OneSignal.LOG_LEVEL.VERBOSE
到 Com.OneSignal.Abstractions.LOG_LEVEL.VERBOSE
.
有一行我不能马上转换到当前的SDK中。
OneSignal.inFocusDisplayType = Com.OneSignal.Abstractions.OSInFocusDisplayOption.Notification;
那么... inFocusDisplayType
在SDK中移动?
完整的代码。
public partial class App : Xamarin.Forms.Application
{
public App ()
{
// The root page of your application
MainPage = new NavigationPage(new MyApp.LoggingInPage());
//Remove this method to stop OneSignal Debugging
OneSignal.Current.SetLogLevel(Com.OneSignal.Abstractions.LOG_LEVEL.VERBOSE, Com.OneSignal.Abstractions.LOG_LEVEL.NONE);
OneSignal.Current.StartInit("YOUR_ONESIGNAL_APP_ID")
.Settings(new Dictionary<string, bool>() {
{ Com.OneSignal.Abstractions.IOSSettings.kOSSettingsKeyAutoPrompt, false },
{ Com.OneSignal.Abstractions.IOSSettings.kOSSettingsKeyInAppLaunchURL, false } })
.EndInit();
OneSignal.inFocusDisplayType = Com.OneSignal.Abstractions.OSInFocusDisplayOption.Notification;
// ^^^^^^^^^^^^^^^^^^ ??
// The promptForPushNotificationsWithUserResponse function will show the iOS push notification prompt. We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 7)
OneSignal.Current.RegisterForPushNotifications();
}
这就是现在的工作方式。
OneSignal.Current.StartInit("YOUR_ONESIGNAL_APP_ID")
.Settings(new Dictionary<string, bool>() {
{ Com.OneSignal.Abstractions.IOSSettings.kOSSettingsKeyAutoPrompt, false },
{ Com.OneSignal.Abstractions.IOSSettings.kOSSettingsKeyInAppLaunchURL, false }
})
.InFocusDisplaying(Com.OneSignal.Abstractions.OSInFocusDisplayOption.Notification) // <-- !
.EndInit();
(感谢 enkaradag的人,他们回应了这一问题。GitHub问题)