iOS SDK
블럭스 iOS SDK 를 설치하고 사용하는 방법을 알아봅니다.
푸시 메시지 연동
Xcode 설정
1
Notification Capability 추가
- Xcode 프로젝트 설정의 Signing & Capabilities 탭에서 + Capabilities를 클릭하세요.

- Push Notifications와 Background Modes를 추가하세요.

- Background Modes에서 Remote notifications를 활성화하세요.

2
Service Extension 설정
- Xcode 프로젝트 상단
File > New > Target을 클릭하고 아래와 같이 Notification Service Extension을 선택하세요.

- 아래와 같이 알맞는 이름을 입력 후 Finish를 클릭하세요.

- 표시되는 팝업에서 Don't Activate를 클릭하여 별도의 Scheme을 활성화하지 않도록 합니다.

- 이후 Notification Service Extension Target의 Minimum Deployments 버전을 현재 사용 중인 메인 앱 Target의 버전과 동일하게 설정합니다.

3
App Group 추가
- Xcode 프로젝트 설정의 Signing & Capabilities 탭에서 + Capability > App Groups 를 선택하여 추가합니다.

group.[Bundle ID].blux이라는 이름의 그룹을 추가합니다. Bundle ID는 메인 앱의 Bundle Identifier와 일치해야 합니다.
- 추가 후 해당 App Group을 활성화하고, 이전 단계에서 만든 Notification Service Extension에도 동일한 App Group을 추가하고 활성화합니다.

4
BluxAppGroupName 키 추가
- Xcode 프로젝트 설정의 Info 탭에서 Custom iOS Target Properties의 마지막 열을 클릭하고 오른쪽에 표시되는 + 버튼을 클릭합니다.

- Key는
BluxAppGroupName, Type은String, Value는 이전 단계에서 만든 App Group의 ID를 입력합니다.
- App Group ID가 변경되는 경우 해당 값도 같이 변경해야 합니다.
3. BluxAppGroupName을 메인 앱 타깃과 Notification Service Extension 타깃 양쪽 모두에 추가해야 합니다. 누락 시 푸시 수신 집계가 되지 않습니다.
SDK 설치
블럭스 iOS SDK는 CocoaPods와 Swift Package Manager로 설치할 수 있어요.
- CocoaPods
- Swift Package Manager
프로젝트의 Podfile을 아래와 같이 설정하세요.
Podfile
// 파일 최상단에 아래 줄을 추가하여 Dynamic Framework를 활성화합니다.
use_frameworks!
target 'YOUR_PROJECT_NAME' do
...
pod 'BluxClient'
end
// 파일 최하단의 아래 줄 추가
// 앞서 입력한 Extension의 Product Name을 target 이름으로 설정합니다.
target 'YOUR_NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME' do
pod 'BluxClient'
end
* Swift Package Manager 설치는 블럭스 iOS SDK 0.6.9 이상에서 지원됩니다.
1
패키지 추가
- Xcode 프로젝트 상단
File > Add Package Dependencies...를 클릭하세요. - 오른쪽 위 검색창에 저장소 주소
https://github.com/zaikorea/Blux-iOS-SDK.git를 입력하세요. - Dependency Rule에서 Up to Next Major Version을 선택하고 Add Package를 클릭하세요.
- Add to Target에서 메인 앱 타깃을 선택하고 Add Package를 클릭하세요.
2
Notification Service Extension 타깃에 추가
앞서 만든 Notification Service Extension 타깃 설정의 General 탭에서 Frameworks and Libraries의 + 버튼을 클릭하고 BluxClient를 추가하세요.
블럭스 SDK 연동
1
AppDelegate.swift 생성 (SwiftUI의 경우)
SwiftUI 프로젝트는 AppDelegate.swift가 존재하지 않기 때문에 별도의 설정이 필요합니다.
AppDelegate.swift 파일을 새로 만들고 기존 <YOUR_PROJECT_NAME>App.swift 파일을 일부 수정합니다.
(추가) AppDelegate.swift
import UIKit
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
}
(기존) <YOUR_PROJECT_NAME>App.swift
struct <YOUR_PROJECT_NAME>App: App {
// 아래 코드 추가
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
}
2
AppDelegate 메서드 추가
- 앱 실행 시,
BluxClient.initialize()메서드 호출 설정application(:didFinishLaunchingWithOptions:)메서드를 추가합니다.
AppDelegate.swiftimport BluxClient
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BluxClient.initialize(
launchOptions,
bluxApplicationId: "BLUX_APPLICATION_ID",
bluxAPIKey: "BLUX_API_KEY",
requestPermissionOnLaunch: true,
) { error in
if let error = error {
// SDK 초기화 실패
Logger.verbose("BluxClient.initialize error: \(error)")
} else {
// SDK 초기화 완료
Logger.verbose("BluxClient.initialize success")
// 자동 로그인의 경우 signIn() 호출
}
}
return true
}
// ...
} - 앱푸시 발송을 위한 푸시 토큰 수집 설정
application(:didRegisterForRemoteNotificationsWithDeviceToken:)메서드를 추가합니다.
AppDelegate.swiftimport BluxClient
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
BluxAppDelegate.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
// ...
}