SSブログ

[プッシュ通知]AppBank Felloを使ってみた

scr_fello1.png
AppBank Felloはプッシュ通知の実装時に必要なサーバー周りの開発を行う必要がなく、数行のコードを追加するだけで利用できます。かつどれだけ使っても無料です。
https://appbank.fello.net/

scr_fello2.PNG

【大まかな流れ】
・iOS dev centerでプロバイダ証明書、プロビジョニングプロファイル作成
 ⇒プロバイダ証明書は(*.cer)→(*.p12)→(*.pem)に変換
・AppBank Felloの管理コンソールにアプリ追加、プロバイダ証明書(*.pem)登録
・XcodeのプロジェクトにAppBank FelloのSDK、Framework、コード追加
 ⇒Bundle ID、プロビジョニングプロファイルは設定しとく
・Macに端末をつないでアプリ実行、プッシュ通知を許可してデバイストーク発行
・AppBank Felloの管理コンソールでプッシュ通知を実行

scr_fello3.PNG

参考
https://fello.net/help/notification_integration_for_ios


■プロバイダ証明書(*.pem)の作成方法
1.iOS dev centerでプロバイダ証明書作成、ダウンロード(*.cer)
2.キーチェーンに追加して書き出し(*.p12)
 ※今回は念のため秘密鍵は選択しない、パスワードは設定しない
3.ターミナルでコマンド実行(*.pem)
 openssl pkcs12 -in <証明書.p12> -out <証明書.pem> -nodes -clcerts
 ※cdコマンドで証明書の保存先に移動しとく
 ※パスワードきかれたら何もせずエンター

[エラー]Missing Push Notification Entitlement

プッシュ通知を実装したアプリを申請したらiTunes Storeから以下のメールが来た。
(アプリのステータスはWaiting For Review)

ーーーーーーーーーーーーーーーーーーーーーーーーー
Missing Push Notification Entitlement - Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement.
If your app uses the Apple Push Notification service, make sure your App ID is enabled for Push Notification in the Provisioning Portal, and resubmit after signing your app with a Distribution provisioning profile that includes the "aps-environment" entitlement.
See "Provisioning and Development" in the Local and Push Notification Programming Guide for more information.
If your app does not use the Apple Push Notification service, no action is required. You may remove the API from future submissions to stop this warning. If you use a third-party framework, you may need to contact the developer for information on removing the API.
If you would like to update your binary for this app, you can reject this binary from the Binary Details page in iTunes Connect. Note that rejecting your binary will remove your app from the review queue and the review process will start over from the beginning when you resubmit your binary.
ーーーーーーーーーーーーーーーーーーーーーーーーー

アプリにプッシュ通知が実装されてるけど、App store公開用のProvisioning Profile にプッシュ通知の設定がちゃんとされてないとゆう内容。
申請の際、Organizerで過去(プッシュ通知設定前)のProvisioning Profileを選択してたかも。

【対処】
念のため申請するアプリのProvisioning Profileの設定が正しか確認して、
Organizerで最新のProvisioning Profileを選択して申請したらうまくいった。
(Provisioning Profileの設定がおかしかったら再作成した方がいいみたい)

▽申請するアプリのProvisioning Profileの設定が正しか確認する方法
・Xcodeの[Window] - [Organizer] - [Archives] - [Distribute] を選択
・「Save for Enterprize ・・・」を選択しNext
・App store公開用のProvisioning Profileを選択しExport
・パッケージファイル(.ipa)保存先を指定しSave
・ターミナルで解凍コマンド実行「unzip <パッケージ.ipa>」
 ※Payload/フォルダに展開される
・ターミナルで署名状況を確認するコマンド実行
 「codesign -d --entitlements :- Payload/<パッケージ.app>」
"aps-environment" があればOK!!
scr_terminal_20140306.png

[プッシュ通知]ニフティクラウドmobile backend を使ってみた

scrpush1.PNG
プッシュ通知を全て自分で実装しようとするとかなり大変。

プッシュ通知用のサーバが必要なので、
自前のサーバがない場合、MySQL付きのレンタルサーバを借りて、テーブル作って、DBにユーザ情報を登録するPHPファイルを準備したり何やら。。

サーバ側の処理を全てしてくれるサービスは幾つかあり、
「ニフティクラウドmobile backend」はそ1つ。(以下、ニフティmBaaSと略す)
つまずいて実装に2日掛かりましたが、めーーーっちゃ楽です。
http://mb.cloud.nifty.com/

無料のBasicプランでもAPIリクエスト・プッシュ通知が200万回/月利用でき、基本ストレージも5GB使用可能。
scrpc1.png


【大まかな流れ】
・iOS dev centerでプロバイダ証明書、プロビジョニングプロファイル作成
 ⇒プロバイダ証明書は(*.cer)→(*.p12)に変換
・ニフティmBaaSの管理コンソールにアプリ追加、プッシュ通知許可、プロバイダ証明書(*.p12)登録
・XcodeのプロジェクトにニフティmBaaSのSDK、Framework、コード追加
 ⇒Bundle ID、プロビジョニングプロファイルは設定しとく
・Macに端末をつないでアプリ実行、プッシュ通知を許可してデバイストーク発行
・ニフティmBaaSの管理コンソールで端末の登録を確認、プッシュ通知を実行

scrpush2.PNG

(参考)
http://mb.cloud.nifty.com/doc/quickstart_ios.html
http://www.lancork.net/2013/10/ios-push-with-nifty-mobile-backend/



★つまずいた所1★
プロバイダ証明書(p12)作成の際、証明書と秘密鍵の両方選択して書き出すと、
管理画面でプッシュ通知すると、「配信エラー」になる。
サポートに問い合わせて解決した↓↓↓
========================================================
●証明書(p12)作成時の注意事項
 ・書き出す際にパスワードを設定しないでください
 ・書き出す際は証明書のみを選択してください
   →証明書に紐付く秘密鍵を選択する必要はありません
========================================================


★つまずいた所2★
iPhone5(ios6.x)でプッシュ通知のテストをしたら、狂った様にサウンドが鳴った(10回くらい)
マナーモードにしてても狂った様にバイブが鳴った(10回くらい)
コードを変更して通知タイプをアラートだけにしたら解決した。

AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
<<変更前>>
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

<<変更後>>
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert)];



★つまずいた所3★
ビルドするとエラーが出る
ーーーーーーーーーーーーーーーーーーーーーーーーーーー
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_CLLocationManager", referenced from:
objc-class-ref in NCMB(NCMBGeoPoint.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ーーーーーーーーーーーーーーーーーーーーーーーーーーー
手順にはないけど、CoreLocation.framework を追加したら解決。


★つまずいた所4★
ビルドするとエラーが出る
ーーーーーーーーーーーーーーーーーーーーーーーーーーー
Undefined symbols for architecture armv7s:
"_OBJC_CLASS_$_FBAccessTokenData", referenced from:
objc-class-ref in NCMB(NCMBFacebookUtils.o)
"_OBJC_CLASS_$_FBRequest", referenced from:
objc-class-ref in NCMB(NCMBFacebookUtils.o)
"_OBJC_CLASS_$_FBSession", referenced from:
objc-class-ref in NCMB(NCMBFacebookUtils.o)
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ーーーーーーーーーーーーーーーーーーーーーーーーーーー
Build Settings >Linking >Other Linker Flagsに「-all_load」や「-ObjC」が設定されていると出るエラー(Facebook SDKの追加が必要)
確かadmob広告用に「-ObjC」を設定してた。
「-ObjC」を消すとアプリが落ちる。。
今回はadmob広告を削除した。。。

[PHPエラー]Unable to send message ID 1: Invalid token (8).

サーバ(プロバイダ)に置いたPHPファイルを実行し、
APNS経由で、iPhone端末(クライアントアプリ)にプッシュ通知のテストをした際に
ブラウザで下記エラーが表示された。

ーーーーーーーーーーーーーーーーーーーーーーーーー
Wed, 26 Feb 2014 02:43:18 +0100 ApnsPHP[15323]: ERROR: Unable to send message ID 1: Invalid token (8).
ーーーーーーーーーーーーーーーーーーーーーーーーー

デバイストークンが無効なのでメッセージを送れないとゆう内容。
PHPファイルに記述してるデバイストークンが間違ってた。

【対処】
端末側でアプリを実行しデバイストークンを取得(Xcodeのログに出力)し、
PHPファイルに正しいデバイストークンを記述したらうまくいった。


[PHPエラー]Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195'

サーバ(プロバイダ)に置いたPHPファイルを実行し、
APNS経由で、iPhone端末(クライアントアプリ)にプッシュ通知のテストをした際に
ブラウザで下記エラーが表示された。

ーーーーーーーーーーーーーーーーーーーーーーーー
Tue, 25 Feb 2014 08:38:54 +0100 ApnsPHP[11935]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...

Tue, 25 Feb 2014 08:38:55 +0100 ApnsPHP[11935]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195': (0)
ーーーーーーーーーーーーーーーーーーーーーーーー


【対処】
「Push Notification用のSSL証明書」を作り直したらうまくいった。
ターミナルで証明書をp12ファイルからpemファイルに変換するのが失敗してたのかも。

ーーーーーーーーーーーーーーーーーーーーーーーー
Wed, 26 Feb 2014 02:24:47 +0100 ApnsPHP[835]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...

Wed, 26 Feb 2014 02:24:49 +0100 ApnsPHP[835]: INFO: Connected to ssl://gateway.sandbox.push.apple.com:2195.
ーーーーーーーーーーーーーーーーーーーーーーーー


以下の設定が全て一致してないとプッシュ通知はうまくいかないので注意が必要。
・ios dev centerのApple ID、プロビジョニングプロファイル
・Push Notification用のSSL証明書(pem)
・ルート証明書(pem)
・PHPファイルのパラメータ
 (SSL証明書、ルート証明書、デバイストークン)
・XcodeのBundle identifier、Code Signing

[エラー]Appの有効な“aps-environment”エンタイトルメント文字列が見つかりません

プッシュ通知のテストの際、Xcodeでビルド・実行した際に、ログに以下のエラーが出力。
※ 端末に「プッシュ通知を送信します。よろしいですか?」のポップアップもなし

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
didFailToRegisterForRemoteNotificationsWithError: Error Domain=NSCocoaErrorDomain Code=3000 "Appの有効な“aps-environment”エンタイトルメント文字列が見つかりません" UserInfo=0x14664340 {NSLocalizedDescription=Appの有効な“aps-environment”エンタイトルメント文字列が見つかりません}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

XcodeでBundle identifier、証明書を設定してなかったのが原因。

【対処】
Xcodeの info > Bundle identifier 設定、
Xcodeの Build Settings > Code Signing > Provisioning Profile 設定。

【結果】
アプリを実行すると、端末に「プッシュ通知を送信します。よろしいですか?」のポップアップが問題なく表示された。

※「Push Notification用のSSL証明書」は事前に申請しとく
※ iTunes connectへのアプリ登録は不要


[リジェクト]Information Needed

アプリを申請した際にリジェクトされた

ーーーーーーーーーーーーーーーーーーーーーーー
We began the review of your app but are not able to continue because we need access to a video that demonstrates your app in use.



-We are not able to reproduce the feature. Would you please provide a demo video to show when the app feature is in use?



You can provide a link to a demo video of your app in iTunes Connect. Go to "Manage Your Applications," select your app, click "Edit" to edit the App Review Information, then scroll to the "Review Notes" section and add the demonstration video access details. Click "Save," then click "Submit New Metadata."



Once this information is available, we can continue your review.
ーーーーーーーーーーーーーーーーーーーーーーー

アプリの機能を再現できないので、アプリ使用方法のデモビデオを提供して欲しいとゆう内容。
何故かこれだけの理由で"Binary Reject"された。
"Binary Reject"されたら"Submit New Metadata"できないし。。

【対処】
アプリ使用方法の動画を作成し
iTunes Connect > "Manage Your Apps" > "対象のアプリ">"Review Notes"
に動画のURLを記述し、再申請。

img20140218.png

作成した動画はこちら↓↓↓


本日公開したアプリはこちら↓↓↓

アプリ申請から公開までの期間は何日??

iPhoneアプリを申請してからAppstore に公開されるまでの期間を計ってみたので記載します。

結論からゆうと、約10日でした。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
2014年2月4日(火) 11:04 申請(Waiting For Review)

2014年2月8日(土) 3:55 審査開始(In Review)

2014年2月8日(土) 8:16 リジェクト(Metadate Reject)

2014年2月9日(日) 17:18 メタデータを修正し再申請(In Review)

2014年2月14日(金) 3:55 審査完了(Ready for Sale)

2014年2月14日(金) 15:40 App store に公開

↑↑↑Appleからくるメールを参照 
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー

ちなみに、本日公開したアプリは以下です。



[エラー]@synthsize of 'weak' property is only allowed in ARC or CC mode

Xcodeでプロジェクトにサンプルコードを追加してビルドした際に下記エラーが発生。

ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
@synthsize of 'weak' property is only allowed in ARC or CC mode
ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
スクリーンショット 2014-02-13 11.19.22.png

@property (nonatomic, weak) UIView *attachedTo;
の'weak' はARC環境じゃないと使えないらしい。

【対処】
propertyの'weak'を"unsafe_unretained" に変更。
スクリーンショット 2014-02-13 11.21.02.png

[エラー2] Apple Mach-O Linker command failed with exit code 1(use -v to see invocation)

以前と同じエラーに2hぐらいハマったのでメモ。
アプリをバージョンアップをする際、過去のプロジェクトをコピペしてビルドした際に下記エラーが発生。
ーーーーーーーーーーーーーーーーーーーーーーーー
Apple Mach-O Linker command failed with exit code 1(use -v to see invocation)
ーーーーーーーーーーーーーーーーーーーーーーーー

【原因】
xcodeのBuild Settings>Search Paths>Library Search Pathsに
過去のパス(広告関連)が残ってるのが原因。
以前、アプリのプロジェクトのフォルダを移動(デスクトップ→別のフォルダ)したので
リンクエラーになってた。
スクリーンショット 2014-02-10 11.15.10.png

【対処】
Admob広告とNend広告のSDKを一旦削除して、再度登録。
xcodeのBuild Settings>Search Paths>Library Search Pathsに
新しいリンクが追加されてた。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。