การย้ายไปยัง Android SDK v.5.x.x บน Xamarin
PushManager
Anchor link toPushManager ประกอบด้วยเมธอดต่าง ๆ สำหรับฟีเจอร์ที่แตกต่างกัน ขณะนี้เมธอดเหล่านี้ได้ถูกแบ่งออกเป็นคลาสต่าง ๆ ดังนี้:
- PushNotificationsManager
- PushwooshNotificationSettings
- PushwooshInApp
- PushwooshBadge
- PushwooshLocation
BaseRegistrationReceiver
Anchor link toBaseRegistrationReceiver ถูกใช้เพื่อจัดการเหตุการณ์การลงทะเบียนและยกเลิกการลงทะเบียนพุช ขณะนี้ receiver นี้ถูกแทนที่ด้วยกลไก callback:
using Pushwoosh;using Pushwoosh.Exception;using Android.Runtime;using Pushwoosh.Function;
class RegistrationListener : Java.Lang.Object, ICallback{ public void Process(Result result) { if (result.IsSuccess) { string token = (string)result.Data; // handle successful registration } else { PushwooshException exception = result.Exception.JavaCast<PushwooshException>(); // handle registration error } }}
PushNotificationsManager.Instance.RegisterForPushNotifications(new RegistrationListener());
BasePushMessageReceiver
Anchor link toBasePushMessageReceiver ถูกใช้เพื่อเลียนแบบพฤติกรรมการแจ้งเตือนของ iOS เมื่อได้รับการแจ้งเตือนพุชในเบื้องหน้า (foreground) ซึ่งทำได้โดยการยกเลิกการแจ้งเตือนที่เข้ามาและเรียกใช้ callback OnMessageReceive วิธีแก้ปัญหาชั่วคราวนี้ต้องการการลงทะเบียนด้วยตนเองเมื่อแอปทำงาน และยกเลิกการลงทะเบียนเมื่อแอปเข้าสู่เบื้องหลัง (background)
receiver นี้ได้ถูกแทนที่ด้วย NotificationServiceExtension:
using Android.App;using Android.OS;using Android.Runtime;using Android.Support.Annotation;using Pushwoosh.Notification;
[assembly: MetaData("com.pushwoosh.notification_service_extension", Value = "com.your.package.YourNotificationServiceExtension")]namespace YourNamespace{ [Register("com/your/package/YourNotificationServiceExtension")] public class YourNotificationServiceExtension : NotificationServiceExtension { protected override bool OnMessageReceived(PushMessage message) { if (IsAppOnForeground) { Handler mainHandler = new Handler(ApplicationContext.MainLooper); mainHandler.Post(() => { HandlePush(message); }); return true; } return false; }
protected override void StartActivityForPushMessage(PushMessage message) { base.StartActivityForPushMessage(message); HandlePush(message); }
[MainThread] void HandlePush(PushMessage message) { //TODO: handle push message } }}
ส่วนขยายนี้ยังใช้เพื่อจัดการเหตุการณ์การมาถึงและการแตะการแจ้งเตือน ซึ่งมาแทนที่โค้ดที่ยุ่งยากทั้งหมดที่ใช้ในการรวม Activity ด้วยตนเอง
PushFragment
Anchor link toPushFragment เป็นทางเลือกที่มีน้ำหนักเบาสำหรับการรวมที่ซับซ้อนซึ่งเกี่ยวข้องกับวงจรชีวิตของ Activity ในทางกลับกัน มันต้องการการสืบทอด FragmentActivity และใช้ Fragment lifecycle ที่ซับซ้อนกว่าโดยนัย
PushFragment และ PushEventListener ขณะนี้ถูกแทนที่ด้วย Pushwoosh#registerForPushNotifications(Callback) และ NotificationServiceExtension
Custom Push Broadcast Receiver (PW_NOTIFICATION_RECEIVER)
Anchor link toPW_NOTIFICATION_RECEIVER ถูกใช้เพื่อปรับแต่งพฤติกรรมของแอปเมื่อผู้ใช้แตะที่การแจ้งเตือน ซึ่งช่วยให้สามารถจัดการการแจ้งเตือนนอกบริบทของ Activity และเปิด Activity ที่แตกต่างกันไปขึ้นอยู่กับเนื้อหาของการแจ้งเตือน การรวมดังกล่าวใช้ API ภายในของ Pushwoosh SDK ซึ่งไม่มีอยู่อีกต่อไป
receiver นี้ถูกแทนที่โดยสมบูรณ์ด้วย NotificationServiceExtension:
using System;using Android.App;using Android.Content;using Android.Runtime;using Pushwoosh.Notification;
[assembly: MetaData("com.pushwoosh.notification_service_extension", Value = "com.your.package.YourNotificationServiceExtension")]namespace YourNamespace{ [Register("com/your/package/YourNotificationServiceExtension")] public class YourNotificationServiceExtension : NotificationServiceExtension { protected override void StartActivityForPushMessage(PushMessage message) { // base.StartActivityForPushMessage(message) starts default launcher activity // or activity marked with ${applicationId}.MESSAGE action. // Simply do not call it to override this behaviour.
// start your activity instead: Intent launchIntent = new Intent(ApplicationContext, typeof(YourActivity)); launchIntent.SetFlags(ActivityFlags.NewTask);
ApplicationContext.StartActivity(launchIntent); } }}
Notification Factory
Anchor link toนอกจากนี้ยังมีการเปลี่ยนแปลงที่สำคัญบางอย่างที่เกี่ยวข้องกับ notification factory:
1. AbsNotificationFactory ถูกแทนที่ด้วย NotificationFactory
2. เมธอด AbsNotificationFactory#onPushReceived(PushData) และ AbsNotificationFactory#onPushHandle(Activity) ถูกแทนที่ด้วยคลาส NotificationServiceExtension (onMessageReceived, startActivityForPushMessage)
3. DefaultNotificationFactory ถูกแทนที่ด้วย PushwooshNotificationFactory
4. PushData ถูกแทนที่ด้วย PushMessage
In-App Messages
Anchor link to1. InAppFacade ถูกแทนที่ด้วย PushwooshInApp
2. อ็อบเจกต์ pushwoosh
ถูกนำมาใช้สำหรับอินเทอร์เฟซเนทีฟของ JavaScript พร้อม API ต่อไปนี้:
getHwid(): string - ส่งคืน Pushwoosh HWID ของอุปกรณ์
getVersion(): string - ส่งคืนเวอร์ชันปัจจุบันของ Pushwoosh SDK
postEvent(event: string, attributes?: object, successCallback?: function, errorCallback?: function) - ส่งคำขอ postEvent
sendTags(tags: object) - ส่งแท็กที่เกี่ยวข้องกับอุปกรณ์
getTags(successCallback: function, errorCallback?: function) - ส่งคืนแท็กที่เกี่ยวข้องกับอุปกรณ์
closeInApp() - ปิดหน้า html ของ In-App
แบ่งปันความคิดเห็นของคุณกับเรา
Anchor link toความคิดเห็นของคุณช่วยให้เราสร้างประสบการณ์ที่ดีขึ้น เราจึงยินดีที่จะรับฟังจากคุณหากคุณมีปัญหาใดๆ ในระหว่างขั้นตอนการรวม SDK หากคุณประสบปัญหาใดๆ โปรดอย่าลังเลที่จะแบ่งปันความคิดเห็นของคุณกับเรา ผ่านแบบฟอร์มนี้