久しぶりにiOSアプリをビルドしようとしたらエラー

ビルドしようとしたら下記のエラー。

No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).

ググったら、こんなん http://stackoverflow.com/questions/22328882/xcode-5-1-no-architectures-to-compile-for-only-active-arch-yes-active-arch-x 出てきた。

なので、言われたとおり、

  • Xcode上でPodsプロジェクトを右クリック→Delete→Remove Reference
  • Xcodeを終了
  • コマンドラインから pod install
  • .xcworkspace を再度開く
  • Podsプロジェクトを選択し、Build Settings→Build Active Architecture Only をNOに (debugがYESになってた)
  • 同じく、自分のプロジェクトのBuild Active Architecture Only もNOに (debugがYESになってた)

したら、iOSシミュレータで動くようになった。よかった。

久しぶりにpod installしたらエラー

rubyのバージョン変えてたので、まずはgemのインストール

gem install cocoapods
rbenv rehash

で、

pod install

すると、エラーが出てくる。 こんなの

Psych::SyntaxError - (/Users/〜〜〜/.cocoapods/repos/master/CocoaPods-version.yml): mapping values are not allowed in this context at line 3 column 4

ググったら、 https://github.com/CocoaPods/CocoaPods/issues/1853 こんなのが出てきたので、書いてあったコマンドを実行

rm -rf ~/.cocoapods/repos/master
pod setup

で、再度

pod install

すると正常に動いた模様。

KFCocoaPodsPlugin をインストールしてみる

前に iOSアプリ開発が捗るXcodeプラグイン - Qiita [キータ]ricobeck/KFCocoaPodsPlugin · GitHub というプラグインが紹介されていました。

便利そうだなーと思いつつ、放置していたのですが、年末年始で少し時間が出来たので、導入してみました。

ただし、githubの説明が

Clone this repo or download the zip, run 'pod install' in the terminal, open the workspace file in Xcode and compile. After a restart of Xcode you have a 'CocoaPods' Menu Item in the Products menu.

しか無かったので、念のためメモ。
※cocoapodsはインストール済みの前提

手順

今回、 ~/bin に入れておくとします。

cd ~/bin
git clone git@github.com:ricobeck/KFCocoaPodsPlugin.git
cd KFCocoaPodsPlugin
pod install
open KFCocoaPodsPlugin.xcworkspace

Xcodeが開くので、Product -> Buildとし、Xcodeを一旦完全に終了させ、再度起動。

すると、公式のgithubにあるように、Productメニュー無いにCocoaPodsが表示されます。
これで入力補完も効くし、黒い画面が無くてもpod install が出来ます。

iOSのPUSH通知用証明書を作成する

PUSH通知用の証明書を作成する手順のキャプチャを貼っておきます。

前提

http://noboru.hatenablog.jp/entry/2013/09/20/023645 の手順を行っている状態。

  • App IDが作成済み
  • 「CertificateSigningRequest.certSigningRequest」が出力済み

手順

iOS Dev Center 右側の「Certificates, Identifiers & Profiles」をクリックします。

「Identifiers」をクリックします。

f:id:suzaku114:20130928004046p:plain

なぜか、すでにApp IDが発行されていました。
おそらく、以前にXcode上で「Fix issue」を押したタイミングで作成されたのではないかと思われます。
「Push Notifications」が「Disabled」なので、「Edit」をクリックします。

f:id:suzaku114:20130928004230p:plain

「Push Notifications」の右側のチェックボックスを選択状態にします。

f:id:suzaku114:20130928004220p:plain

すると、下のボタンが有効になるので、まずは「Development SSL Certificate」の「Create Certificate...」をクリックします。

f:id:suzaku114:20130928004213p:plain

なんか、以前に見たことがある画面が表示されました。
「Continue」を押します。

f:id:suzaku114:20130928004205p:plain

前回作成した「CertificateSigningRequest.certSigningRequest」を選択し、「Generate」ボタンをクリックします。

f:id:suzaku114:20130928004158p:plain

「Download」ボタンをクリックします。
aps_development.cer」がダウンロードされます。開発環境(Sandbox)用の証明書です。

f:id:suzaku114:20130928004151p:plain

Typeが「APNs Development iOS」となっている証明書が作成されました。 本番用もとりあえず作成しておきたいので、再度「App IDs」をクリックします。

f:id:suzaku114:20130928004144p:plain

「Push Notifications」の「Development」側が「Enabled」になりました。
「Distribution」側は、「Configurable」となっているので、再度「Edit」をクリックします。

f:id:suzaku114:20130928004136p:plain

今度は、「Production SSL Certificate」の「Create Certificate...」をクリックします。

f:id:suzaku114:20130928004130p:plain

「Continue」をクリックします。

f:id:suzaku114:20130928011003p:plain

「CertificateSigningRequest.certSigningRequest」を選択し、「Generate」をクリックします。

f:id:suzaku114:20130928010955p:plain

本番用の証明書が作成されました。
「Download」をクリックすると、「aps_production.cer」がダウンロードされます。

f:id:suzaku114:20130928010948p:plain

Typeが「APNs Production iOS」となっている証明書が作成されました。
「App IDs」をクリックします。

f:id:suzaku114:20130928010942p:plain

「Distribution」側も「Enable」になりました。

f:id:suzaku114:20130928010934p:plain

ダウンロードした「aps_development.cer」・「aps_production.cer」をそれぞれダブルクリック(or Cmd+O)すると、キーチェーンアクセスが起動し、登録されます。

f:id:suzaku114:20130928013229p:plain

Developmentの証明書を右クリックし、「...を書き出す...」をクリックします。

f:id:suzaku114:20130928013232p:plain

ファイル名は「aps_development.p12」とでもしておきます。
フォーマットは「p12」とします。

f:id:suzaku114:20130928013909p:plain

パスワードは空で、そのままOKとします。(ホントは、ちゃんと設定しましょう)

f:id:suzaku114:20130928013905p:plain

パスワードを聞かれるので、Macのアカウントのパスワードを入力します。

f:id:suzaku114:20130928013901p:plain

指定したフォルダに「aps_development.p12」が作成されました。
同様の手順で、productionの証明書についても、「aps_production.p12」を作成しておきます。

ターミナルでp12ファイルがあるディレクトリまで移動し、下記を実行する。

openssl pkcs12 -in aps_development.p12 -out aps_development.pem -nodes -clcerts

aps_development.pem が作成されました。
これを使えば、PUSH通知が送れるはず、です。(まだやってない。

感想

思ったよりは簡単に出来た。

参考

http://ameblo.jp/econa-77

CocoaPodsをインストールしてみた。

Mac OS X 10.8.2
Ruby関連は、アップデートはしてないはず。


基本的には下記を参考。
http://d.hatena.ne.jp/Watson/20111204/mac_dev_jp_advent_calendar_cocoapods01
なので、下記コマンドを実行。

sudo gem install cocoapods
略
Installing ri documentation for i18n-0.6.4...
Installing ri documentation for multi_json-1.6.1...
Installing ri documentation for activesupport-3.2.12...

unrecognized option `--encoding'

For help on options, try 'rdoc --help'

とか出てましたが、とりあえず気にせずに下記を実行。

pod --help

結果:

Your RubyGems version (1.3.6) is too old, please update with: `gem update --system`

ということで、言われた通り、下記を実行。

sudo gem update --system

すると、大量にログが出力されましたが、気にせず再度実行。

pod --help

なんか、それっぽいヘルプが出てきたので、下記を実行。

pod setup

すると、下記の出力。

Setting up CocoaPods master repo
Cloning spec repo `master' from `https://github.com/CocoaPods/Specs.git' (branch `master')

Cocoapods 0.17.0.rc4 is available.

Setup completed (read-only access)

とりあえず、セットアップは出来たらしい。

なので、TumeKyouen.xcodeproj が存在するディレクトリで

vim Podfile

で、内容に下記を記載。

platform :ios
dependency 'AFNetworking'


それでは、インストール

pod install TumeKyouen.xcodeproj

怒られた。

[!] Unrecognized argument: `TumeKyouen.xcodeproj'
pod install

とすると、

[DEPRECATED] `dependency' is deprecated (use `pod')
Resolving dependencies of `./Podfile'
Updating spec repositories

Cocoapods 0.17.0.rc4 is available.

Resolving dependencies for target `default' (iOS 4.3)
[!] AFNetworking (1.1.0) is not compatible with iOS 4.3.

との表示。

Podfileに

xcodeproj 'TumeKyouen.xcodeproj'

を追記し、

pod install

を実行しても、特に変化はなし。


で、PodfileのdependencyをAFNetworkingから、下記に変更。

dependency 'AdMob'

で、再度インストール

pod install

で、結果、

[DEPRECATED] `dependency' is deprecated (use `pod')
Resolving dependencies of `./Podfile'
Updating spec repositories

Cocoapods 0.17.0.rc4 is available.

Resolving dependencies for target `default' (iOS 4.3)
Downloading dependencies
Installing AdMob (6.3.0)
Generating support files

[!] From now on use `TumeKyouen.xcworkspace'.
Integrating `libPods.a' into target `TumeKyouen' of Xcode project `./TumeKyouen.xcodeproj'.

[!] The target `TumeKyouen [Debug - Release]' overrides the `OTHER_LDFLAGS' build setting defined in `Pods/Pods.xcconfig'.
    - Use the `$(inherited)' flag, or
    - Remove the build settings from the target.

あれ、通った?
とりあえず、

open TumeKyouen.xcworkspace

を実行したら、エラーになってしまって、よく考えると、TumeKyouen.xcodeproj を開いたままだったので、Xcodeを全て閉じ、再度

open TumeKyouen.xcworkspace

とすると、無事、開いて、ビルドも成功。
とりあえず、今日はここまで。

  • 3/16 追記

もともと入れていた、AdMobのリソースを削除したところ、コンパイルエラーになってしまった。
そこで、TumeKyouenプロジェクト -> Build Phases -> Link Binary With Libraries に、libGoogleAdMobAds.a を追加したところ、コンパイルが通るようになった。

iPhoneアプリへのAdMob導入のために行ったこと


基本的には公式ドキュメントを参照
https://developers.google.com/mobile-ads-sdk/docs/ios/fundamentals?hl=ja


ライブラリのコピー

  • AppDelegateがあるフォルダ(グループ)に"GoogleAdMobAdsSdkiOS"フォルダを作成し、ダウンロードしたzip内のREADME.txt以外のファイルをコピー

(フォルダ階層については、他のサンプルなどを確認し、要変更)


エラーの解決

"_OBJC_CLASS_$_ASIdentifierManager", referenced from:

ビルド時に、上記のエラーが発生したため、
http://www.j7lg.com/archives/1497
を参考に、AdSupport.frameworkを追加

上記を設定後もビルド時に、

"_OBJC_CLASS_$_SKStoreProductViewController", referenced from

上記のエラーが発生したため、
http://stackoverflow.com/questions/12726640/build-error-while-add-revmob-add-in-ios-app
を参考にStoreKit.frameworkを追加

 -[GADObjectPrivate changeState:]: unrecognized selector sent to instance

が出力されていたため、下記を参考に、該当のTARGETSのOther Linker Flagsに"-ObjC"を設定(Debug, Release両方に設定される)
http://stackoverflow.com/questions/12635283/admob-crashes-with-gadobjectprivate-changestate-unrecognized-selector


最終的に追加したframework一覧

  • AudioToolbox
  • MessageUI
  • SystemConfiguration
  • CoreGraphics
  • AdSupport
  • StoreKit