iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 16
0
Software Development

30 天上手 iOS App 開發系列 第 20

30 天上手 iOS App 開發 DAY 20

「如何使用Firebase Cloud Messaging在iOS實現推播的功能」(上篇)


推播(Push Notification)是App中很重要的一個功能,有了推播就會吸引使用者的目光在你的App,有效的提升使用者開啟App的頻率,例如:購物App在特殊節日時釋出買一送一,即時發送推播給使用者,此時大部分的消費者都會因好奇而打開App查看是什麼商品買一送一。

當然除了Firebase Cloud Messaging(FCM)還有其他實現iOS app推播的方法,但FCM個人覺得用起來較簡單,所以本篇針對FCM來教大家推播的應用。


第一步:設定Apple Developer Account

首先,你必須有一個Apple developer account(需年付99美金),才能使用推播的功能。

有了帳號之後,進入 https://developer.apple.com/ 點擊右上方Account登入你的帳號。
登入後會進入到下圖的畫面,接著點擊左方的「Certificates, IDs & Profiles.」

https://ithelp.ithome.com.tw/upload/images/20180117/20107506rDWwtv25l5.png

接著點擊左方列表的「App IDs」,在這可以看到這個開發者帳號的所有有註冊的App。
點擊右上方「+」號,如下圖。

https://ithelp.ithome.com.tw/upload/images/20180117/20107506lOO2ESlMhk.png

接著會看到下圖的畫面。

https://ithelp.ithome.com.tw/upload/images/20180117/20107506hZpxDgHRYC.pnghttps://ithelp.ithome.com.tw/upload/images/20180117/201075067NlOA0QaGw.png

這邊需要填入以下資料:

  • App ID Description— Name:填入你的App名稱
  • App ID Suffix — Explicit App ID — Bundle ID:填入你自訂的App Bundle Identifier(如com.itbook.fcmdemo)
  • App Services - 勾選Push Notification
    完成上方步驟後,點選「Continue」,在下個頁面點選「Register」。

https://ithelp.ithome.com.tw/upload/images/20180117/20107506kAgSnW0nTn.png

接著回到「App IDs」頁面,找到你剛剛註冊的App Name,展開後點擊Edit。

https://ithelp.ithome.com.tw/upload/images/20180117/20107506XPpgYNyDM5.pnghttps://ithelp.ithome.com.tw/upload/images/20180117/20107506vJOaJ3zwfv.png

進入後往下滑找產生測試時期通知的SSL證書(Development SSL Certificate),點擊Create Certificate。

https://ithelp.ithome.com.tw/upload/images/20180117/20107506a7056c77b7.png

接著我們需要從KeyChain產生一個認證登入請求(CSR)檔來上傳。


從 key chain 匯出 .certSigningRequest (CSR) 檔案

打開鑰匙圈,選擇左上鑰匙圈存取→憑證輔助程式→從憑證授權要求憑證

https://ithelp.ithome.com.tw/upload/images/20180117/201075064XoShz0DcC.png

接著填入以下資訊:

  • 使用者電子郵件位址:開發帳號 的 email
  • 一般名稱:英文名字
  • 已將要求:儲存到磁碟
    按繼續後即輸出完成

https://ithelp.ithome.com.tw/upload/images/20180117/20107506Imz4FgOttl.png


有CSR檔了,接著回到apple開發帳號後台那邊吧!
上傳CSR檔後點選「Continue」。
https://ithelp.ithome.com.tw/upload/images/20180118/20107506wKs4yFGM98.png
https://ithelp.ithome.com.tw/upload/images/20180117/20107506XD6nb2Y3eJ.png

接著點擊「Download」來下載你的憑證,下載後直接點擊兩下,系統會自動安裝到鑰匙圈。

https://ithelp.ithome.com.tw/upload/images/20180117/20107506M2zqdIKmgd.png

到鑰匙圈檢查是否安裝到鑰匙圈

https://ithelp.ithome.com.tw/upload/images/20180117/20107506fZx4whIe9F.png

找到後展開,選擇 輸出「你的英文名字」

https://ithelp.ithome.com.tw/upload/images/20180118/201075062bZ0hNOyuS.png

注意檔案格式需為 (.p12)

https://ithelp.ithome.com.tw/upload/images/20180118/20107506FZnLJByIhI.png

點選儲存後系統會詢問是否輸入密碼來保護該檔案,可以直接選擇「好」來跳過該提示,也可自行輸入密碼來保護,但請牢記該密碼,因為在下篇時上傳到 Firebase 時會用到。

https://ithelp.ithome.com.tw/upload/images/20180118/20107506zoCrNIGNDU.png


恭喜你!目前已經完成所有準備工作,

提醒各位記得將最後一個步驟的.p12檔儲存好,下篇將會從Firebase設定開始!


上一篇
30 天上手 iOS App 開發 DAY 19
下一篇
30 天上手 iOS App 開發 DAY 21
系列文
30 天上手 iOS App 開發28
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言