Difference between revisions of "Firebase 教學說明"

From AdLocus
Jump to: navigation, search
m (→‎加入 SDK Library)
(→‎Firebase 設定完成)
 
(16 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
== 加入 Firebase 專案 ==
 
== 加入 Firebase 專案 ==
 
* [https://console.firebase.google.com AdLocus 登入Firebase控制台]
 
* [https://console.firebase.google.com AdLocus 登入Firebase控制台]
−
* FCM APNs 推播金鑰設定 設定:https://firebase.google.com/docs/cloud-messaging/ios/certs
+
* 建立專案後依照指示將 Firebase 新增至您的 iOS 應用程式即可開始使用
 +
** 選擇 iOS 版本
 +
** 註冊應用程式
 +
** 下載設定檔
 +
*** 將您剛才下載的 GoogleService-Info.plist 檔案移到 Xcode 專案的根目錄中,並將該檔案新增到所有目標中
 +
** 新增 Firebase SDK
 +
*** Google 服務會用 CocoaPods 來安裝和管理依附元件。請開啟終端機視窗,然後前往應用程式的 Xcode 專案位置
 +
** 新增初始化程式碼
 +
*** 如要在應用程式啟動時連線至 Firebase,請將下方的初始化程式碼加入主要 AppDelegate 類別
  
−
== 設定 Info.plist ==
+
== 為Firebase 加入 APN 驗證金鑰 ==
−
* 在 Info.plist 中加入
+
* 上傳您的APNs身份驗證密鑰
−
** App Transport Security Settings
+
** 將您的APNs身份驗證密鑰上載到Firebase。如果您還沒有APNs身份驗證密鑰,請參閱[https://firebase.google.com/docs/cloud-messaging/ios/certs 使用FCM配置APNs]
−
*** Allow Arbitrary Loads  =  YES
+
** 在Firebase控制台的項目內部,選擇齒輪圖標,選擇Project Settings ,然後選擇Cloud Messaging選項卡
−
** FirebaseAppDelegateProxyEnabled
+
** 在iOS應用配置下的APNs身份驗證密鑰中 ,單擊“上載”按鈕
−
*** FirebaseAppDelegateProxyEnabled = NO
+
** 瀏覽到保存密鑰的位置,選擇它,然後單擊“ 打開” 。添加密鑰的密鑰ID(可在[https://developer.apple.com/membercenter/index.action Apple Developer Member Center]中的證書,標識符和配置文件中找到),然後單擊Upload
  
−
* 地區堆播需要使用者開啟以下地理位置使用權限
+
== Firebase 設定完成 ==
−
** Privacy - Location Usage Description
+
* 現在您已經可以使用Firebase 雲端通訊功能
−
** Privacy - Location Always and When In Use Usage Description
+
* 專案預設會開啟 Firebase Cloud Messaging API (V1)  
−
** Privacy - Location When In Use Usage Description
+
    [[File:FirebaseCloudMessagingAPI_1.jpeg|800px]]
−
<pre>
+
* 產生新的私密金鑰
−
Important
+
    [[File:FirebaseCloudMessagingAPI_2.jpeg|800px]]
−
* Privacy - Location Always Usage Description
+
* 提供產出的 Json 檔案
−
 
+
    [[File:FirebaseCloudMessagingAPI_3.jpeg|800px]]
−
This key is required if your iOS app uses APIs that access the user’s location at all times and deploys to targets earlier than iOS 11.
+
−
</pre>
+
−
 
+
−
[[File:ios_infoplist.jpg|1200px]]
+
−
 
+
−
== 設定編譯相容性 ==
+
−
* 在 Build Setting 中 Embedded Content Contains Swift Code 設為 YES
+
−
[[File:ios_embedded_contents_swift.jpg|900px]]
+
−
 
+
−
* Release 時移除模擬器用的 binary 檔:
+
−
** 在 Build Phases 中加入 Run Script
+
−
[[File:ios_run_script_0.jpg|900px]]
+
−
 
+
−
** 並填入:
+
−
<syntaxhighlight lang='bash'>
+
−
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
+
−
 
+
−
# This script loops through the frameworks embedded in the application and
+
−
# removes unused architectures.
+
−
find "$APP_PATH" -name 'AdLocus.framework' -type d | while read -r FRAMEWORK
+
−
do
+
−
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
+
−
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
+
−
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
+
−
 
+
−
EXTRACTED_ARCHS=()
+
−
 
+
−
for ARCH in $ARCHS
+
−
do
+
−
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
+
−
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
+
−
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
+
−
done
+
−
 
+
−
echo "Merging extracted architectures: ${ARCHS}"
+
−
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
+
−
rm "${EXTRACTED_ARCHS[@]}"
+
−
 
+
−
echo "Replacing original executable with thinned version"
+
−
rm "$FRAMEWORK_EXECUTABLE_PATH"
+
−
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
+
−
 
+
−
done
+
−
</syntaxhighlight>
+
−
 
+
−
[[File:ios_run_script_1.jpg|900px]]
+
−
 
+
−
== iOS Capabilities 設定 ==
+
−
* 在Capabilities 中開啟 Background Mode 並勾選
+
−
** Background fetch
+
−
** Location updates
+
−
** Remote Notifications
+
−
[[File:ios_backgroundfetch.jpg|1200px]]
+
−
 
+
−
* 在Capabilities 中開啟 Push Notifications
+
−
[[File:Notifications.jpg|1200px]]
+

Latest revision as of 22:01, 23 September 2024

加入 Firebase 專案

  • AdLocus 登入Firebase控制台
  • 建立專案後依照指示將 Firebase 新增至您的 iOS 應用程式即可開始使用
    • 選擇 iOS 版本
    • 註冊應用程式
    • 下載設定檔
      • 將您剛才下載的 GoogleService-Info.plist 檔案移到 Xcode 專案的根目錄中,並將該檔案新增到所有目標中
    • 新增 Firebase SDK
      • Google 服務會用 CocoaPods 來安裝和管理依附元件。請開啟終端機視窗,然後前往應用程式的 Xcode 專案位置
    • 新增初始化程式碼
      • 如要在應用程式啟動時連線至 Firebase,請將下方的初始化程式碼加入主要 AppDelegate 類別

為Firebase 加入 APN 驗證金鑰

  • 上傳您的APNs身份驗證密鑰
    • 將您的APNs身份驗證密鑰上載到Firebase。如果您還沒有APNs身份驗證密鑰,請參閱使用FCM配置APNs
    • 在Firebase控制台的項目內部,選擇齒輪圖標,選擇Project Settings ,然後選擇Cloud Messaging選項卡
    • 在iOS應用配置下的APNs身份驗證密鑰中 ,單擊“上載”按鈕
    • 瀏覽到保存密鑰的位置,選擇它,然後單擊“ 打開” 。添加密鑰的密鑰ID(可在Apple Developer Member Center中的證書,標識符和配置文件中找到),然後單擊Upload

Firebase 設定完成

  • 現在您已經可以使用Firebase 雲端通訊功能
  • 專案預設會開啟 Firebase Cloud Messaging API (V1)
   FirebaseCloudMessagingAPI 1.jpeg
  • 產生新的私密金鑰
   FirebaseCloudMessagingAPI 2.jpeg
  • 提供產出的 Json 檔案
   FirebaseCloudMessagingAPI 3.jpeg