第3章 ネイティブ iOS (Swift)
3.1. ダウンロード
ビルドファームを使ってビルドした Swift ベースの iOS アプリについて、enterprise distribution 証明書を使用して署名する場合、アプリが起動時にクラッシュする可能性があります。
この問題が発生した場合は、問題の解決方法の詳細について、Red Hat ナレッジベースの記事「Swift-based iOS application crashes upon startup when signed using an enterprise distribution certificate without Organisational Unit field」を参照してください。
3.2. スタート
この SDK により、iOS バージョン 8 以上の Swift アプリで RHMAP API を使用することができます。
RHMAP iOS Swift SDK は、Github の FeedHenry iOS SDK リポジトリー でホストされるオープンソースのプロジェクトです。ご自由にプロジェクトのフォークを行い、このプロジェクトに貢献してください。
この SDK を使用する前に:
- Xcode IDE をインストールします。Xcode は Apple 開発者ポータルからダウンロードできます。
CocoaPods 依存関係管理システムをインストールします。CocoaPods をインストールするには以下を実行します。
sudo gem install cocoapods
詳細は、CocoaPods web サイトにある『Getting Started guide』を参照してください。
3.2.1. 新規アプリ
サンプルアプリ をクローンし、RHMAP iOS Swift SDK が CocoaPods の依存関係として組み込まれた新規 iOS アプリケーションを使って開始します。
git clone https://github.com/feedhenry-templates/blank-ios-swift.git
Podfile で定義された依存関係を取得します。
pod install
Xcode で blank-ios-app.xcworkspace ワークプレースを開きます。必要な依存関係は Pods グループにあります。
3.2.2. 既存アプリ
アプリに Podfile がない場合、以下の内容の Podfile という新規ファイルをプロジェクトのルートに作成してください。
source 'https://github.com/CocoaPods/Specs.git' xcodeproj 'ProjectName.xcodeproj' platform :ios, '8.0' use_frameworks! pod 'FeedHenry', '4.0.0'
4.0.0 をターゲットにしている RHMAP iOS Swift SDK のバージョンに、ProjectName.xcodeproj をプロジェクトの名前に置き換えます。バージョン番号を指定しない場合、CocoaPods 中央リポジトリーの最新バージョンが使用されます。
Podfile で定義された依存関係を取得します。
pod install
Xcode で ProjectName.xcworkspace を開けるようになります。
3.2.3. セットアップ
アプリが RHMAP サーバーと通信できるようにするプロパティーを定義する必要があります。以下の値を fhconfig.plist 設定ファイルに追加します。
<?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>host</key> <string>__RHMAP_Core_host__</string> <key>appid</key> <string>__Client_App_ID__</string> <key>projectid</key> <string>__Project_ID__</string> <key>appkey</key> <string>__Client_App_ API_key___</string> <key>connectiontag</key> <string>__Connection_tag__</string> </dict> </plist>
クライアントアプリとクラウドアプリ間の通信についての詳細は、「Projects - Connections」を参照してください。
3.2.4. 初期化
RHMAP iOS Swift SDK からクラウド要求を呼び出す前に、初期化する必要があります。以下のコードスニペットを App Delegate の application(_, didFinishLaunchingWithOptions:) メソッドか、またはコードがクラウド要求前に確実に呼び出されるその他の場所にコピーします。
import FeedHenry
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FH.init { (resp:Response, error: NSError?) -> Void in
if let error = error {
print("Error: \(error)")
return
}
print("Response: \(resp.parsedResponse)")
}
return true
}3.3. API ドキュメント
API Docs: すべてのクライアント API についてのドキュメント

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.