การตั้งค่า Swift Package Manager
ข้อกำหนด
Anchor link to- สร้างบัญชี Pushwoosh หากคุณยังไม่มี
- เครื่อง Mac ที่มี Xcode เวอร์ชันใหม่ (Apple Silicon เท่านั้น)
- ใบรับรอง iOS Push ดูรายละเอียดได้ที่: การกำหนดค่า iOS
การผสานการทำงาน
Anchor link to- เปิดโปรเจกต์ของคุณใน Xcode และไปที่ การตั้งค่าของโปรเจกต์ (project’s settings) -> Package Dependencies -> และกดปุ่ม ’+’

- ป้อน Package URL ต่อไปนี้:
https://github.com/Pushwoosh/PushwooshVision-XCFramework
- ตั้งค่า Dependency Rule

- ในหน้าจอถัดไป เพื่อเลือก Package ของคุณ ให้เลือก Pushwoosh Package และ Add Package ไปยัง Target ของแอปหลักของคุณ

- เปิด Main App Target ของคุณ และภายใต้ Frameworks, Libraries, and Embedded Content ตรวจสอบให้แน่ใจว่าได้เพิ่ม Pushwoosh iOS SDK แล้ว

- ยอดเยี่ยม! คุณได้ผสาน Pushwoosh visionOS SDK เข้ากับโปรเจกต์ของคุณเรียบร้อยแล้ว
เพิ่ม Capabilities ที่จำเป็น
Anchor link to- เลือกโปรเจกต์ราก (1) และ Target ของแอปหลักของคุณ (2) จากนั้นไปที่แท็บ Signing and Capabilities
- กดปุ่ม + Capability (3) และเลือกความสามารถ Push Notifications
- จากนั้นเพิ่มความสามารถ Background Modes และเลือกช่องทำเครื่องหมาย Remote notifications (4)

- ยอดเยี่ยม! การกำหนดค่า Xcode capabilities เสร็จสมบูรณ์
เพิ่มโค้ดสำหรับเริ่มต้น Pushwoosh
Anchor link to- เพิ่มโค้ดต่อไปนี้ใน App ของคุณ
import SwiftUIimport Pushwoosh
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate, PWMessagingDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
Pushwoosh.sharedInstance().registerForPushNotifications() Pushwoosh.sharedInstance().delegate = self return true }
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Pushwoosh.sharedInstance().handlePushRegistration(deviceToken) }
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: any Error) { Pushwoosh.sharedInstance().handlePushRegistrationFailure(error) print("\(error.localizedDescription)") }
func pushwoosh(_ pushwoosh: Pushwoosh, onMessageOpened message: PWMessage) { print("Message opened: \(message.payload!)") }
func pushwoosh(_ pushwoosh: Pushwoosh, onMessageReceived message: PWMessage) { print("Message received: \(message.payload!)") }}
@mainstruct newdemoApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene { WindowGroup { ContentView() } }}
- ใน
Info.plist
ของคุณ เพิ่มคีย์ประเภทสตริงต่อไปนี้:
<key>Pushwoosh_APPID</key><string>XXXXX-XXXXX</string>
<key>Pushwoosh_API_TOKEN</key><string>YOUR_DEVICE_API_TOKEN</string>
Pushwoosh_APPID
: Pushwoosh Application Code ของคุณPushwoosh_API_TOKEN
: Pushwoosh Device API Token ของคุณ
สำคัญ: ตรวจสอบให้แน่ใจว่าได้ให้สิทธิ์การเข้าถึงโทเค็นกับแอปพลิเคชันที่ถูกต้องใน Pushwoosh Control Panel ของคุณ เรียนรู้เพิ่มเติม

- ยอดเยี่ยม! ตอนนี้คุณสามารถส่งการแจ้งเตือนแบบพุชครั้งแรกของคุณได้แล้ว!


แบ่งปันความคิดเห็นของคุณกับเรา
Anchor link toความคิดเห็นของคุณช่วยให้เราสร้างประสบการณ์ที่ดีขึ้น เราจึงยินดีที่จะรับฟังจากคุณหากคุณพบปัญหาใดๆ ในระหว่างขั้นตอนการผสาน SDK หากคุณประสบปัญหาใดๆ โปรดอย่าลังเลที่จะแบ่งปันความคิดเห็นของคุณกับเรา ผ่านแบบฟอร์มนี้