Difference between revisions of "Firebase 教學說明"

From AdLocus
Jump to: navigation, search
m (加入 Firebase 專案)
m
Line 13: Line 13:
  
 
* FCM APNs 推播金鑰設定 設定:https://firebase.google.com/docs/cloud-messaging/ios/certs
 
* FCM APNs 推播金鑰設定 設定:https://firebase.google.com/docs/cloud-messaging/ios/certs
 
== 設定 Info.plist ==
 
* 在 Info.plist 中加入
 
** App Transport Security Settings
 
*** Allow Arbitrary Loads  =  YES
 
** FirebaseAppDelegateProxyEnabled
 
*** FirebaseAppDelegateProxyEnabled = NO
 
 
* 地區堆播需要使用者開啟以下地理位置使用權限
 
** Privacy - Location Usage Description
 
** Privacy - Location Always and When In Use Usage Description
 
** Privacy - Location When In Use Usage Description
 
<pre>
 
Important
 
* Privacy - Location Always Usage Description
 
 
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]]
 

Revision as of 11:13, 27 August 2020

加入 Firebase 專案

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