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
github "Pushwoosh/pushwoosh-mac-sdk"
หรืออีกวิธีหนึ่ง คุณสามารถลากและวางเฟรมเวิร์กไปที่ 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 PushKitimport Pushwoosh
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//โค้ดเริ่มต้นจำนวนมากของคุณ
//-----------ส่วนของ PUSHWOOSH-----------
NSUserNotificationCenter.default.delegate = Pushwoosh.sharedInstance()?.notificationCenterDelegateProxy
// ตั้งค่า delegate แบบกำหนดเองสำหรับการจัดการ push ในกรณีของเราคือ view controllerPushwoosh.sharedInstance().delegate = self
// การจัดการ push เมื่อแอปเริ่มทำงานPushwoosh.sharedInstance().handlePushReceived(aNotification.userInfo)
// ลงทะเบียนเพื่อรับ push notifications!Pushwoosh.sharedInstance().registerForPushNotifications()
#import <Pushwoosh/Pushwoosh.h>
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ //โค้ดเริ่มต้นจำนวนมากของคุณ
//-----------ส่วนของ PUSHWOOSH-----------
[NSUserNotificationCenter defaultUserNotificationCenter].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 ไปยัง PWMessagingDelegatefunc application(_ application: NSApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Pushwoosh.sharedInstance()?.handlePushRegistration(deviceToken)}
// callback ข้อผิดพลาดในการลงทะเบียน push notification ของระบบ, delegate ไปยัง PWMessagingDelegatefunc application(_ application: NSApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { Pushwoosh.sharedInstance()?.handlePushRegistrationFailure(error)}
// callback การลงทะเบียน push notification ของระบบสำเร็จ, delegate ไปยัง pushManager- (void)application:(NSApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[Pushwoosh sharedInstance] handlePushRegistration:deviceToken];}
// callback ข้อผิดพลาดในการลงทะเบียน push notification ของระบบ, delegate ไปยัง pushManager- (void)application:(NSApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [[Pushwoosh sharedInstance] handlePushRegistrationFailure:error];}
เพื่อจัดการ push notifications ให้เพิ่มฟังก์ชันต่อไปนี้ไปยัง UIApplicationDelegate ของคุณ (ไฟล์เดียวกับสามขั้นตอนข้างต้น):
//event นี้จะทำงานเมื่อได้รับ pushfunc 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))")}
//event นี้จะทำงานเมื่อได้รับ push- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageReceived:(PWMessage *)message { NSLog(@"onMessageReceived: %@", message.payload);}
//event นี้จะทำงานเมื่อผู้ใช้แตะที่การแจ้งเตือน- (void)pushwoosh:(Pushwoosh *)pushwoosh onMessageOpened:(PWMessage *)message { NSLog(@"onMessageOpened: %@", message.payload);}
การเปิดใช้งาน Push Notifications
Anchor link toไปที่ Signing and Capabilities ใน target ของคุณ กด + Capability และเพิ่ม Push Notifications
