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

การตั้งค่า Swift Package Manager

ข้อกำหนดเบื้องต้น

Anchor link to
  • สร้างบัญชี Pushwoosh หากคุณยังไม่มี
  • เครื่อง Mac ที่มี Xcode เวอร์ชันใหม่ (เฉพาะ Apple Silicon)
  • ใบรับรอง iOS Push Certificate ดูรายละเอียดที่: การกำหนดค่า iOS

การผสานการทำงาน

Anchor link to
  1. เปิดโปรเจกต์ของคุณใน Xcode และไปที่ การตั้งค่าของโปรเจกต์ (project’s settings) -> Package Dependencies -> และกดปุ่ม ’+’
  1. ป้อน Package URL ต่อไปนี้:

https://github.com/Pushwoosh/PushwooshVision-XCFramework

  1. ตั้งค่า Dependency Rule
  1. ในหน้าจอถัดไป เพื่อเลือก Package ของคุณ ให้เลือก Pushwoosh Package และ Add Package ไปยัง Target ของแอปหลักของคุณ
  1. เปิด Main App Target ของคุณและภายใต้ Frameworks, Libraries, and Embedded Content ตรวจสอบให้แน่ใจว่า Pushwoosh iOS SDK ได้ถูกเพิ่มเข้ามาแล้ว
  1. ยอดเยี่ยม! คุณได้ผสานการทำงาน Pushwoosh visionOS SDK เข้ากับโปรเจกต์ของคุณเรียบร้อยแล้ว

เพิ่ม Capabilities ที่จำเป็น

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

เพิ่มโค้ดสำหรับเริ่มต้น Pushwoosh

Anchor link to
  1. เพิ่มโค้ดต่อไปนี้ลงในแอปของคุณ
import SwiftUI
import 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!)")
}
}
@main
struct newdemoApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
  1. ในไฟล์ 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 ของคุณ เรียนรู้เพิ่มเติม

  1. ยอดเยี่ยม! ตอนนี้คุณสามารถส่ง push notification แรกของคุณได้แล้ว!

แบ่งปันความคิดเห็นของคุณกับเรา

Anchor link to

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