Missing Push Notification Entitlement
みなさんおはこんばんにちは、エンジニアの石橋です。
今回はPush通知に付いて話そうかと思います。
Xcode8からはPush Notificationに関する署名をきちんと設定しなければいけなくなりました。
設定しないと申請時にMissing Push Notification Entitlement
という内容のメールで却下されます。
これに対応するのは簡単でCapabilities -> Push NotificationsをONとすれば自動的にAppName.entitlementsファイルが作成されます。
ただ、これをビルド毎にやるのは少々面倒なので自動化します。
1) 以下の内容のファイルをAssets以下に配置します
ファイル名はproduction.entitlements
とします。
<?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>aps-environment</key> <string>production</string> </dict> </plist>
2) Unityのビルドを自動化します。
以下の内容のファイルをAssets/Editor以下に配置します。
こちらはファイル名はなんでもよいです。
using UnityEditor; using UnityEngine; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; using System.IO; public class Hoge { static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath ) { string projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj"; PBXProject proj = new PBXProject(); proj.ReadFromString( File.ReadAllText( projPath ) ); string target = proj.TargetGuidByName( "Unity-iPhone" ); var debug = proj.BuildConfigByName( target, "Debug" ); var release = proj.BuildConfigByName( target, "Release" ); var fileName = "production.entitlements"; var src = Path.Combine( Application.dataPath, fileName ); var dest = Path.Combine( buildPath, fileName ); File.Copy( src, dest ); proj.AddFileToBuild( target, proj.AddFile( dest, fileName, PBXSourceTree.Source ) ); proj.SetBuildPropertyForConfig( debug, "CODE_SIGN_ENTITLEMENTS", fileName ); proj.SetBuildPropertyForConfig( release, "CODE_SIGN_ENTITLEMENTS", fileName ); proj.WriteToFile( projPath ); } }
3) 最後にipa出力後にきちんと設定されているかを確認します。
- 出力したipaをzipにリネームして解凍
- Terminalで1で解凍したPayloadフォルダへ移動
codesign -d --entitlements :- Payload/パッケージ.app
とコマンドを打ちproductionで設定されていればOKです。