MobiVMでビルドしたアプリがiCloud Driveにアクセスできるようにする
はじめに
今回は、MobiVMでビルドしたアプリが、GKSavedGame等の機能の利用時にiCloud Driveにアクセスできるようにする方法を共有します。
MobiVMについては以下の前回記事をご確認ください。
deep-verdure.hatenablog.com
MobiVMでビルドしたアプリが、本記事の対応をせずにiCloud Driveにアクセスしようとすると、以下のようなエラーメッセージが出力されます。
Error Domain=GKErrorDomain Code=27 "The requested operation could not be completed because you are not signed in to iCloud or have not enabled iCloud Drive" UserInfo={NSLocalizedDescription=The requested operation could not be completed because you are not signed in to iCloud or have not enabled iCloud Drive}
Entitlements.plist.xmlの追加
MobiVMではRoboVMと同様に、Xcodeプロジェクトファイルが存在しません。そのため、iCloud Driveの利用に必要な資格設定をXcode上で実施できません。
ではどうすればよいのかというと、通常はXcodeが自動出力する、資格情報を記述したファイルであるEntitlements.plist.xmlを手動作成し、MoviVMプロジェクト直下(robovm.xmlと同じ場所)に格納します。
そして、robovm.xmlに以下の一行を追加し、ipaビルド時に自作したEntitlements.plist.xmlが参照されるようにします。
<iosEntitlementsPList>Entitlements.plist.xml</iosEntitlementsPList>
Entitlements.plist.xmlの内容も掲載します。「iCloud Containers IDを指定」となっている箇所には、払出済みのiCloud Containers IDを指定してください。
設定内容の詳細は、以下の公式リファレンスをご確認ください。
https://developer.apple.com/documentation/bundleresources/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>com.apple.developer.icloud-container-environment</key> <array> <string>Production</string> </array> <key>com.apple.developer.icloud-container-identifiers</key> <array> <string><!-- iCloud Containers IDを指定 --></string </array> <key>com.apple.developer.icloud-services</key> <array> <string>CloudDocuments</string> </array> <key>com.apple.developer.ubiquity-container-identifiers</key> <array> <string><!-- iCloud Containers IDを指定 --></string> </array> </dict> </plist>