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

ตัวอย่างโค้ด iOS

ด้วยตัวอย่างของ Pushwoosh สำหรับ iOS คุณสามารถสำรวจฟังก์ชันการทำงานของ Pushwoosh ได้โดยไม่ต้องรวม SDK เข้ากับโปรเจกต์ของคุณ หรือตรวจสอบว่า Pushwoosh SDK ถูกนำไปใช้อย่างไรในโปรเจกต์ตัวอย่างของเรา

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

Anchor link to

ก่อนใช้ตัวอย่าง โปรดตรวจสอบให้แน่ใจว่าคุณมีสิ่งต่อไปนี้:

แอปพลิเคชันตัวอย่าง Pushwoosh

Anchor link to

โปรเจกต์นี้เป็นแอปพลิเคชัน iOS พื้นฐานที่รวม Pushwoosh SDK ไว้ด้วย ซึ่งแสดงฟีเจอร์หลักต่างๆ เช่น:

  • การรับการแจ้งเตือนแบบพุช
  • การติดตามการส่งการแจ้งเตือนแบบพุช
  • การจัดการแท็กผู้ใช้
  • การส่งอีเวนต์
  • การลงทะเบียนผู้ใช้

ใช้แอปตัวอย่างเป็นเครื่องมือในการเรียนรู้หรือเป็นรากฐานสำหรับการพัฒนาของคุณ

1. ดาวน์โหลดแอปตัวอย่าง

Anchor link to

โคลน repository:

Terminal window
git clone https://github.com/Pushwoosh/pushwoosh-ios-sample.git

2. กำหนดค่าโปรเจกต์

Anchor link to
  1. Open the project in Xcode.

  2. Add https://github.com/Pushwoosh/Pushwoosh-XCFramework as Swift Package Dependency.

  3. Set the bundle identifier for the main target (PushwooshSampleApp) to match your Pushwoosh project (e.g., com.pushwoosh.PushwooshSampleApp).

  4. Use the same bundle identifier for the NotificationService target, appending .NotificationService (e.g., com.pushwoosh.PushwooshSampleApp.NotificationService).

  5. In Info.plist, set the:

Important: Be sure to give the token access to the right app in your Pushwoosh Control Panel. Learn more

3. รันโปรเจกต์

Anchor link to
  1. บิวด์และรันโปรเจกต์
  2. ไปที่แท็บ Settings ในแอป
  3. แตะปุ่ม Register for Pushes
  4. ให้สิทธิ์สำหรับการแจ้งเตือนแบบพุช อุปกรณ์จะถูกลงทะเบียนกับ Pushwoosh

แอปพลิเคชัน Quickstart ของ Pushwoosh

Anchor link to

คอลเลกชัน Quickstart ประกอบด้วยโปรเจกต์แต่ละโปรเจกต์ ซึ่งแต่ละโปรเจกต์จะแสดงฟีเจอร์ SDK ที่เฉพาะเจาะจง ใช้สิ่งเหล่านี้เป็นข้อมูลอ้างอิงหรือเป็นจุดเริ่มต้นสำหรับแอปของคุณ

1. ดาวน์โหลดแอปพลิเคชัน Quickstart

Anchor link to

โคลนโปรเจกต์ตัวอย่างจาก GitHub:

Terminal window
git clone https://github.com/Pushwoosh/pushwoosh-quickstart-ios.git

2. สำรวจโปรเจกต์

Anchor link to

แต่ละโฟลเดอร์มีโปรเจกต์ที่ปรับให้เหมาะกับฟีเจอร์เฉพาะ:

3. กำหนดค่าและรัน

Anchor link to
  1. เปิดโปรเจกต์ใน Xcode
  2. ตั้งค่า bundle identifier ให้ตรงกับโปรเจกต์ Pushwoosh ของคุณ
  3. คัดลอก Application Code จาก Pushwoosh Dashboard
  4. ใน Info.plist ตั้งค่าคีย์ Pushwoosh_APPID เป็น Application Code
  5. บิวด์และรันโปรเจกต์
  6. ใช้ Pushwoosh Control Panel เพื่อส่งการแจ้งเตือนแบบพุชและดูการทำงานของมัน