คู่มือการผสานรวมขั้นสูงของ iOS SDK
ส่วนนี้ให้ข้อมูลเกี่ยวกับการผสานรวมขั้นสูงของ Pushwoosh iOS SDK
โหมดพื้นหลัง
Anchor link toหากต้องการเปิดใช้งานฟังก์ชันนี้ คุณต้องเพิ่ม Background Modes ให้กับโปรเจกต์ของคุณ
ขั้นตอนการเปิดใช้งานโหมดพื้นหลัง
Anchor link to- เปิดโปรเจกต์ของคุณใน Xcode และเลือกใน Project Navigator
- เลือก app target ของคุณจากแผงด้านซ้าย
- ไปที่แท็บ Signing & Capabilities
- คลิกปุ่ม + Capability ที่มุมซ้ายบน
- ค้นหาและเลือก Background Modes จากรายการ
- ในส่วน Background Modes ให้เปิดใช้งาน Remote notifications โดยทำเครื่องหมายที่ช่อง
เมื่อเสร็จสิ้น แอปของคุณจะสามารถจัดการ push notifications รวมถึง silent ones ได้ในขณะที่ทำงานในโหมดพื้นหลัง
โหมดเบื้องหน้า
Anchor link toโดยค่าเริ่มต้น Pushwoosh iOS SDK จะแสดง notification banner เมื่อแอปทำงานในโหมดเบื้องหน้า
คุณสามารถควบคุมพฤติกรรมนี้ได้โดยการตั้งค่า boolean flag ต่อไปนี้ในโค้ดของคุณ (เช่น ใน AppDelegate ของคุณ):
// Set false to disable foreground notifications, true to enable itPushwoosh.sharedInstance().showPushnotificationAlert = true// Set 0 to disable foreground notifications, 1 to enable it[[Pushwoosh sharedInstance] setShowPushnotificationAlert:0];ระดับ Log
Anchor link toPushwoosh iOS SDK รองรับระดับการ logging ต่อไปนี้:
NONE- ไม่มี log จาก SDKERROR- แสดงเฉพาะข้อความ error ใน consoleWARNING- แสดง warnings นอกเหนือจาก errorsINFO- รวมถึงข้อความ informational (การตั้งค่าเริ่มต้น)DEBUG- รวมถึงข้อมูล debug โดยละเอียด
โดยค่าเริ่มต้น ระดับการ logging ถูกตั้งค่าเป็น INFO เพื่อให้มั่นใจว่า SDK จะให้ข้อมูลที่เกี่ยวข้องโดยไม่ทำให้ developer console รก
หากต้องการแก้ไขระดับการ logging ให้อัปเดตคีย์ Pushwoosh_LOG_LEVEL ในไฟล์ Info.plist ของแอปคุณ:
<key>Pushwoosh_LOG_LEVEL</key><string>YOUR_LOG_LEVEL</string>อีกทางเลือกหนึ่ง คุณสามารถเปลี่ยนระดับ log โดยใช้โค้ดสั้นๆ ด้านล่างนี้:
Pushwoosh.Debug.setLogLevel(.PW_LL_DEBUG)แทนที่ YOUR_LOG_LEVEL ด้วยระดับที่ต้องการ (เช่น DEBUG หรือ ERROR)
UNNotificationCenterDelegate แบบกำหนดเอง
Anchor link toหากคุณต้องการใช้ UNNotificationCenterDelegate ของคุณเอง (เช่น สำหรับ local notifications) คุณควรแจ้ง Pushwoosh SDK เกี่ยวกับเรื่องนี้เพื่อให้ทำงานได้อย่างถูกต้อง คุณสามารถทำได้ด้วยคุณสมบัติ notificationCenterDelegateProxy ของ Pushwoosh instance:
Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy.add(my_delegate)[Pushwoosh.sharedInstance.notificationCenterDelegateProxy addNotificationCenterDelegate:my_delegate];จากนั้น ให้ implement เมธอด UNNotificationCenterDelegate ใน delegate ของคุณ:
func userNotificationCenter( _ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { if (!PWMessage.isPushwooshMessage(notification.request.content.userInfo)) { // Handle your notification completionHandler(UNNotificationPresentationOptions.alert) }}
func userNotificationCenter( _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if (!PWMessage.isPushwooshMessage(response.notification.request.content.userInfo)) { // Handle your notification completionHandler() }}- (void)userNotificationCenter:(UNNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { if (![PWMessage isPushwooshMessage:notification.request.content.userInfo]) { // Handle your message completionHandler(UNNotificationPresentationOptionAlert); }}
- (void)userNotificationCenter:(UNNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { if (![PWMessage.isPushwooshMessage:response.notification.request.content.userInfo]) { // Handle your message completionHandler(); }}การเริ่มต้น Pushwoosh แบบ Lazy Initialization
Anchor link toflag Pushwoosh_LAZY_INITIALIZATION จะป้องกันการเริ่มต้น Pushwoosh SDK โดยอัตโนมัติเมื่อแอปพลิเคชันเริ่มต้น ซึ่งช่วยให้ควบคุมได้มากขึ้นว่าบริการ Pushwoosh SDK จะเริ่มต้นเมื่อใด
เมื่อเปิดใช้งาน flag นี้ Pushwoosh SDK จะไม่เริ่มบริการจนกว่าเมธอด Pushwoosh iOS SDK จะถูกเรียกอย่างชัดเจน
เพิ่มรายการต่อไปนี้ลงใน Info.plist:
<key>Pushwoosh_LAZY_INITIALIZATION</key><true/>กรณีการใช้งาน
-
การเริ่มต้น SDK ที่ควบคุมได้ – flag Pushwoosh_LAZY_INITIALIZATION ช่วยให้สามารถหน่วงเวลาการเริ่มต้น Pushwoosh SDK ได้ ทำให้ควบคุมได้มากขึ้นว่าบริการ push จะเปิดใช้งานเมื่อใด
-
การเปิดใช้งาน Push แบบหน่วงเวลา – ในบางแอปพลิเคชัน push notifications ควรเริ่มต้นภายใต้เงื่อนไขเฉพาะเท่านั้น การเปิดใช้งาน flag นี้ทำให้มั่นใจได้ว่า Pushwoosh SDK จะเริ่มต้นเมื่อมีการร้องขออย่างชัดเจนเท่านั้น
-
การกำหนดค่า Push เฉพาะผู้ใช้ – บางแอปพลิเคชันอาจต้องการปรับแต่งการตั้งค่า push notification ตามความต้องการของผู้ใช้หรือการตั้งค่าบัญชี ด้วย lazy initialization, Pushwoosh SDK จะเริ่มต้นหลังจากกำหนดค่าที่เหมาะสมแล้วเท่านั้น
รายการคุณสมบัติ Info.plist ทั้งหมด
Anchor link to| Property | Description | Possible Values |
|---|---|---|
Pushwoosh_APPID | ตั้งค่า Pushwoosh application ID สำหรับ production build | XXXXX-XXXXX Type: String |
Pushwoosh_APPID_Dev | ตั้งค่า Pushwoosh application ID สำหรับ development build | XXXXX-XXXXX Type: String |
Pushwoosh_SHOW_ALERT | แสดง notification foreground alert | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_ALERT_TYPE | ตั้งค่า notification alert style | BANNER (ค่าเริ่มต้น) / ALERT / NONE Type: String |
Pushwoosh_BASEURL | แทนที่ Pushwoosh server base URL | https://cp.pushwoosh.com/json/1.3/ (ค่าเริ่มต้น) Type: String |
Pushwoosh_AUTO_ACCEPT_DEEP_LINK_FOR_SILENT_PUSH | หาก YES, Deep Links ที่ได้รับใน silent pushes จะถูกประมวลผลโดยอัตโนมัติ | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_ALLOW_SERVER_COMMUNICATION | อนุญาตให้ SDK ส่ง network requests ไปยัง Pushwoosh servers | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_DATA | อนุญาตให้ SDK รวบรวมและส่ง device data (OS version, locale, และ model) ไปยัง server | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_OS_VERSION | อนุญาตให้ SDK รวบรวมและส่ง OS version ของ device ไปยัง server | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_LOCALE | อนุญาตให้ SDK รวบรวมและส่ง device locale ไปยัง server | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_ALLOW_COLLECTING_DEVICE_MODEL | อนุญาตให้ SDK รวบรวมและส่ง device model ไปยัง server | YES (ค่าเริ่มต้น) / NO Type: Boolean |
Pushwoosh_LOG_LEVEL | ระดับการ logging ของ Pushwoosh SDK สำหรับรายละเอียด โปรดดูที่ การควบคุมระดับ Log | NONE / ERROR / WARNING / INFO (ค่าเริ่มต้น) / DEBUG / VERBOSE Type: String |
Pushwoosh_PURCHASE_TRACKING_ENABLED | อนุญาตให้ SDK ติดตาม in-app purchases จำเป็นสำหรับ Customer Journey Builder | YES / NO (ค่าเริ่มต้น) Type: Boolean |