Hướng dẫn tạo APNs Authentication Key để gửi nhận thông báo trên Firebase Cloud Messaging(FCM)

Để gửi và nhận được thông báo FCM trên thiết bị apple bạn cần thiết lập Apple Push Notification Service, khi thực hiện 1 lệnh gửi thông báo phía server của ứng dụng sẽ cần gửi thông báo đến APNs sau đó APNs mới thực hiện chuyển tiếp thông báo đến thiết bị của người dùng cuối, mô hình hoạt động như bên dưới:

Để thực cài đặt và sử dụng APNs bạn có thể thực hiện các bước bên dưới:

Bước 1: Tạo Certificate Signing Request trên MacOS:

Keychain Access => Certificate Assistant => Request a Certificate from a Certificate Authority. => Nhập email => Save to Disk(hệ thống sẽ xuất ra 1 file, bạn cần lưu file này để thực hiện bước tiếp theo)

Bước 2: Tạo Certificates trên tài khoản Developer của Apple theo Link.

Certificates, Identifiers & Profiles => Certificates => New => Apple Push Notification service SSL(Sandbox & Production) => Continue => chọn App ID => Continue => Upload Certificate Signing Request đã xuất được ở bước 1 => Continue => xuất ra file CSR(bạn cần lưu file này để thực hiện bước tiếp theo)

Chọn Apple Push Notification service SSL(Sandbox & Production)
Chọn App ID
Upload Certificate Signing Request đã xuất được ở bước 1

Bước 3: Tạo Key trên tài khoản Developer của Apple theo link

Certificates, Identifiers & Profiles => Keys => New => Nhập tên và Apple Push Notifications Service(APNs) => Continues => upload file csr ở bước trước => download file P8.(bạn cần lưu file này để thực hiện bước tiếp theo)

Ở phần này do mình đã tạo hết số key cho phép nên sẽ báo limit, tài khoản của các bạn chưa có thì có thể chọn bình thường nhé

Bước 4: Thêm key vừa P8 vừa tạo vào Firebase Console.

Truy cập console firebase => chọn vào app ios(chưa có thì tạo mới theo hướng dẫn) => Cloud messaging=> APNs Authentication Key => upload file p8 ở bước trên + Key Id(lấy ở key đã tạo ở bước 3) + TeamId(lấy ở trong tài khoản Apple developer) => Done

Như vậy đã hoàn tất các bước thiết lập, chúc các bạn thành công!

Leave a Comment