ข้ามไปยังเนื้อหา

การผสานการทำงาน Geozones กับ MAUI Dotnet

การผสานฟังก์ชัน Geozones เข้ากับแอปพลิเคชัน MAUI .NET ของคุณนั้นทำได้ง่ายดายด้วย Pushwoosh ทำตามขั้นตอนเหล่านี้เพื่อเริ่มต้น:

  1. เพิ่ม Pushwoosh.DotNet.Geozones NuGet Package ไปยังโซลูชันของคุณ
  1. การผสานการทำงานกับ Android

ในโปรเจกต์ Android ของคุณ ให้ค้นหาไฟล์ MainActivity.cs และเรียกใช้ LocationManager.Init() ในเมธอด OnCreate():

using PushwooshSDK.DotNet.Geozones.Android;
...
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
PushManager.Init();
LocationManager.Init();
}
}
  1. การผสานการทำงานกับ iOS

สำหรับโปรเจกต์ iOS ของคุณ ให้เปิดไฟล์ AppDelegate.cs และเรียกใช้ LocationManager.Init() ในเมธอด FinishedLaunching():

using Pushwoosh.iOS;
using PushwooshSDK.DotNet.Geozones.iOS;
using UIKit;
...
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
PushManager.Init();
LocationManager.Init();
return base.FinishedLaunching(application, launchOptions);
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
  1. เพิ่มการอนุญาตเข้าถึงตำแหน่งที่ตั้งตามข้อกำหนดของแอปของคุณ

ควรเพิ่มการอนุญาต Privacy - Location When In Use Usage Description เสมอ

5. จากนั้นเริ่มการติดตามตำแหน่งที่ตั้งโดยการเรียกใช้เมธอด StartLocationTracking()

using PushwooshSDK.DotNet.Geozones;
...
LocationManager.Instance.StartLocationTracking();