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

Mac OS X

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

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

Anchor link to

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

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

หรืออีกวิธีหนึ่ง คุณสามารถลากและวาง framework ไปที่ 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 ของคุณ เพิ่มคีย์ประเภท string Pushwoosh_APPID โดยมี Pushwoosh Application Code ของคุณเป็นค่า

การแก้ไข AppDelegate

Anchor link to

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

import PushKit
import Pushwoosh
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//lots of your initialization code
//-----------PUSHWOOSH PART-----------
NSUserNotificationCenter.default.delegate = Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy
// set custom delegate for push handling, in our case - view controller
Pushwoosh.sharedInstance().delegate = self
// handling push on app start
Pushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
// register for push notifications!
Pushwoosh.sharedInstance().registerForPushNotifications()

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

// system push notification registration success callback, delegate to PWMessagingDelegate
func application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)
}
// system push notification registration error callback, delegate to PWMessagingDelegate
func application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)
}

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

//this event is fired when the push gets received
func pushwoosh(_ pushwoosh: Pushwoosh!, onMessageReceived message: PWMessage!) {
print("onMessageReceived: \(String(describing: message.payload))")
}
//this event is fired when user taps the notification
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