コンテンツにスキップ

iOSアプリ向けの設定

iOSアプリ向けの設定を行います。
Flutterビルドで生成されたXcodeプロジェクトに対して行います。


Xcodeプロジェクトの設定

RichFlyer SDK for iOSマニュアルを参照してXcodeの設定を実施してください。


UISceneライフサイクルへの対応

iOS 27 SDKでビルドするアプリでは、UISceneライフサイクルへの対応が必要です。
本SDKを利用するiOSアプリでは、Flutter 3.38以上を使用し、Deployment TargetをiOS 13.0以上に設定してください。Flutter 3.41以上の使用を推奨します。

Flutter 3.41以降で自動移行されたプロジェクトも、以下のAppDelegate.swiftInfo.plistの設定になっていることを確認してください。

AppDelegate.swiftの編集

AppDelegate.swiftを以下のように編集します。
RichFlyerの通知delegateは、FlutterエンジンやSceneの初期化より前に設定してください。

import Flutter
import UIKit
import richflyer_sdk_flutter

@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
  private let richFlyerNotificationHandler = RFNotificationHandler()

  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    SwiftRichflyerSdkFlutterPlugin.configureNotificationDelegate(
      richFlyerNotificationHandler
    )

    return super.application(
      application,
      didFinishLaunchingWithOptions: launchOptions
    )
  }

  func didInitializeImplicitFlutterEngine(
    _ engineBridge: FlutterImplicitEngineBridge
  ) {
    GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
  }
}

この設定により、通知からアプリを起動するコールドスタート時にも通知情報を処理できます。
また、RichFlyer SDKはSceneのアクティブ/非アクティブ通知を監視するため、アプリが非アクティブになったタイミングで行うセグメント登録やイベント送信も引き続き実行されます。

Info.plistの編集

Runner/Info.plist<dict>直下に以下を追加し、SceneのdelegateにFlutterSceneDelegateを指定します。

<key>UIApplicationSceneManifest</key>
<dict>
    <key>UIApplicationSupportsMultipleScenes</key>
    <false/>
    <key>UISceneConfigurations</key>
    <dict>
        <key>UIWindowSceneSessionRoleApplication</key>
        <array>
            <dict>
                <key>UISceneClassName</key>
                <string>UIWindowScene</string>
                <key>UISceneConfigurationName</key>
                <string>flutter</string>
                <key>UISceneDelegateClassName</key>
                <string>FlutterSceneDelegate</string>
                <key>UISceneStoryboardFile</key>
                <string>Main</string>
            </dict>
        </array>
    </dict>
</dict>

複数Sceneについて

Flutterは複数Sceneを完全にはサポートしていないため、UIApplicationSupportsMultipleScenesfalseに設定してください。

旧バージョンからの移行

従来のAppDelegate.swiftを使用している場合は、以下のように移行してください。

変更前 変更後
@UIApplicationMain @main
RFCustomAppDelegate RFNotificationHandler
SwiftRichflyerSdkFlutterPlugin.register(delegate:) SwiftRichflyerSdkFlutterPlugin.configureNotificationDelegate(_:)
didFinishLaunchingWithOptions内のGeneratedPluginRegistrant.register(with: self) didInitializeImplicitFlutterEngine内のGeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)

RFCustomAppDelegateは既存アプリとの互換性のため残されていますが、新規実装ではRFNotificationHandlerを使用してください。


Cocoa Pods

Cocoapodsのインストール

作業を実施する前に開発を行うPCにCocoaPodsがインストールされている必要があります。

Podfileの編集

生成されたXcodeプロジェクト(Runner.xcworkspaceファイル)と同じディレクトリにあるPodfileファイルに追記します。
下記の NotificationContentNotificationService は、 Xcodeプロジェクトの設定 で作成したApp Extensionの名前に替えて反映してください。

Podfile

target 'Runner' do
    use_frameworks!
    use_modular_headers!

    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

    target 'NotificationContent' do
        inherit! :search_paths
    end

    target 'NotificationService' do
        inherit! :search_paths
    end
end

設定反映

以下のコマンドを実行して設定を反映します。

pod update

Info

コマンド実行前にXcodeプロジェクトが開かれていたら終了させてください。