---
# System prepended metadata

title: PayEasy iOS SDK 整合指南
tags: [SDK文件]

---

# PayEasy iOS SDK 整合指南
## 系統需求
* iOS 15.0
* Xcode 16
* CocoaPods 套件管理工具
## 安裝步驟
### 1. 設定 CocoaPods
1. 透過XCode打開專案目錄 將.xcodeproj直接拖入Terminal取得位置：
```
cd 專案位置/專案名稱.xcodeproj <= 將 /專案名稱.xcodeproj 刪除
```
2. 初始化 Podfile:
```
pod init
```
3. 開啟Podfile:
```
open podfile
```
4. 編輯Podfile內容:
```
platform :ios, '15.0'
target '專案名稱' do
  use_frameworks!
  pod 'Firebase/Analytics'
end
```
5. 儲存並關閉Podfile 輸入以下指令安裝相依套件
```
pod install
```
### 2. 引入框架
在 Xcode 專案的 General > Frameworks, Libraries, and Embedded Content 中加入以下框架：
* GoogleAppMeasurementIdentitySupport.framework
* GoogleAppMeasurement.framework
* FirebaseAnalytics.framework
* IOS_x_17Life.framework
* KeychainAccess.framework

完成後應該要長這樣
![App引入Framework](https://hackmd.io/_uploads/BJitLIQv1g.png)
### 3. 設定Keychain Sharing
1. 在 Xcode 中開啟 Sign & Capabilities
2. 點擊左上角 "+" 按鈕
3. 搜尋並添加 "Keychain Sharing"
4. 在 Keychain Sharing 中加入您的 App Bundle Identifier

完成後應該要長這樣
![Capability新增Keychain Sharing](https://hackmd.io/_uploads/Sy4KLImvkg.png)

### 4. 配置Info.plist
在 Info.plist 中加入以下權限設定 注意更改裡面的CFBundleURLName：
```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <!-- 位置權限 -->
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>我們會依照你的位置顯示附近的店家</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>我們會依照你的位置顯示附近的店家</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>我們會依照你的位置顯示附近的店家</string>
    
    <!-- 相機和相簿權限 -->
    <key>NSPhotoLibraryUsageDescription</key>
    <string>允許「PayEasy福利網」使用你的相簿嗎？</string>
    <key>NSCameraUsageDescription</key>
    <string>允許「PayEasy福利網」使用你的相機嗎？</string>
    
    <!-- URL Scheme 設定 -->
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>你的BundleID</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>payeasystore</string>
            </array>
        </dict>
    </array>
    
    <!-- 外部應用程式支援 -->
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>comgooglemaps</string>
    </array>
</dict>
</plist>
```

完成後應該要長這樣
![Info設定](https://hackmd.io/_uploads/H1F_UImvkg.png)


並且到GoogleAnalytics下載GCM_PayEasyStore_test下載ios版本的GoogleService-Info.plist![截圖 2025-01-14 上午11.26.07](https://hackmd.io/_uploads/r1GjFLQvke.png)

將下載好GoogleService-Info.plist放入專案目錄內
![截圖 2025-01-14 上午11.31.45](https://hackmd.io/_uploads/ByDTqIQw1g.png)

### 5. 使用範例
```
import Firebase
import IOS_x_17Life
import SwiftUI

struct ContentView: View {
    @State var channelId: String = "2754d156-2844-41d4-bc10-78b50691f868"
    @State var member_id: String = "1"
    @State var enterprise_id: String = "8"
    @State var shouldNavigate: Bool = false
    @FocusState var isFocused: Bool
    @State var urlId: String = "" // 為了使分享的連結可以跳轉到指定商店頁面

    public init() {
        print("!DEBUG FirebaseApp.configure")
        FirebaseApp.configure()
    }

    var body: some View {
        NavigationView {
            VStack(spacing: 10) {
                NavigationLink(
                    destination: HomeView(
                        channelId: channelId,
                        member_id: Int(member_id) ?? 0,
                        enterprise_id: Int(enterprise_id) ?? 0,
                        shops_id: urlId
                    ),
                    isActive: Binding(
                        get: { shouldNavigate || !urlId.isEmpty },
                        set: { _ in
                            shouldNavigate = false
                            urlId = ""
                        }
                    )
                ) {
                    EmptyView()
                }

                Text("channelId")
                    .frame(maxWidth: .infinity, alignment: .leading)
                TextField("channelId", text: $channelId)
                    .focused($isFocused)

                Text("member_id")
                    .frame(maxWidth: .infinity, alignment: .leading)
                TextField("member_id", text: $member_id)
                    .keyboardType(.numberPad)
                    .focused($isFocused)

                Text("enterprise_id")
                    .frame(maxWidth: .infinity, alignment: .leading)
                TextField("enterprise_id", text: $enterprise_id)
                    .keyboardType(.numberPad)
                    .focused($isFocused)

                Button(action: {
                    print(channelId)
                    print(member_id)
                    print(enterprise_id)
                    shouldNavigate = true
                }) {
                    Text("HomeView")
                }
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
        }
        .frame(width: .infinity, height: .infinity)
        .navigationViewStyle(StackNavigationViewStyle()) // 避免嵌套問題
        .navigationBarTitleDisplayMode(.inline)
        .navigationBarBackButtonHidden(true) // 確保隱藏系統返回按鈕
        .onTapGesture {
            isFocused = false
        }
        .handleDeepLink()
    }
}

#Preview {
    ContentView()
}
```