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

Mac OS X

ดาวน์โหลด SDK
โปรเจกต์ตัวอย่าง
เอกสาร SDK API

การเชื่อมโยง Pushwoosh.framework

Anchor link to

เพิ่ม Pushwoosh.framework ไปยังโปรเจกต์ของคุณผ่านตัวจัดการ dependency โดยใส่บรรทัดต่อไปนี้ใน podfile หรือ cartfile ของคุณ:

platform :osx, '10.7'
target 'MyApp' do
pod 'Pushwoosh_mac'
end

หรืออีกวิธีหนึ่ง คุณสามารถลากและวางเฟรมเวิร์กไปที่ Link Binaries With Libraries ใน Build Phases ของโปรเจกต์ของคุณได้เลย

การเพิ่มไลบรารี

Anchor link to

ในแท็บ Build Phases ของโปรเจกต์ของคุณ เปิด Link Binaries With Libraries และคลิกที่ Add items (ปุ่ม ”+”) ค้นหาและเพิ่มไลบรารี libz.tbd และ libc++.tbd ไปยังโปรเจกต์ของคุณ:

การเชื่อมโยงแอปกับ Pushwoosh Control Panel

Anchor link to

ใน Info.plist ของคุณ ให้เพิ่มคีย์ประเภทสตริง Pushwoosh_APPID โดยมี Pushwoosh Application Code ของคุณเป็นค่า

การแก้ไข AppDelegate

Anchor link to

เพิ่มโค้ดต่อไปนี้ไปยัง AppDelegate ของคุณ:

import PushKit
import Pushwoosh
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//โค้ดเริ่มต้นจำนวนมากของคุณ
//-----------ส่วนของ PUSHWOOSH-----------
NSUserNotificationCenter.default.delegate = Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy
// ตั้งค่า delegate แบบกำหนดเองสำหรับการจัดการ push ในกรณีของเราคือ view controller
Pushwoosh.sharedInstance().delegate = self
// การจัดการ push เมื่อแอปเริ่มทำงาน
Pushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
// ลงทะเบียนเพื่อรับ push notifications!
Pushwoosh.sharedInstance().registerForPushNotifications()

เพิ่มโค้ดต่อไปนี้ไปยัง UIApplicationDelegate ของคุณ (ไฟล์เดียวกับด้านบน)

// callback การลงทะเบียน push notification ของระบบสำเร็จ, delegate ไปยัง PWMessagingDelegate
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)
}
// callback ข้อผิดพลาดในการลงทะเบียน push notification ของระบบ, delegate ไปยัง PWMessagingDelegate
func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)
}

เพื่อจัดการ push notifications ให้เพิ่มฟังก์ชันต่อไปนี้ไปยัง UIApplicationDelegate ของคุณ (ไฟล์เดียวกับสามขั้นตอนข้างต้น):

//event นี้จะทำงานเมื่อได้รับ push
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {
print("onMessageReceived: \(String(describing: message.payload))")
}
//event นี้จะทำงานเมื่อผู้ใช้แตะที่การแจ้งเตือน
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageOpened message: PWMessage!) {
print("onMessageOpened: \(String(describing: message.payload))")
}

การเปิดใช้งาน Push Notifications

Anchor link to

ไปที่ Signing and Capabilities ใน target ของคุณ กด + Capability และเพิ่ม Push Notifications