UnityAppController.hに書いてあるdelegate相当の機能を使用すればできます
@interface TestAppController : UnityAppController
@end
@implementation TestAppController
- (void)startUnity:(UIApplication*)application
{
[super startUnity:application];
// 初期化
[Parse setApplicationId:@"" clientKey:""];
UIApplication* app = [UIApplication sharedApplication];
[app registerForRemoteNotificationTypes: ( UIRemoteNotificationTypeBadge
| UIRemoteNotificationTypeSound
| UIRemoteNotificationTypeAlert )];
}
// 「このアプリはプッシュ通知を送信します。よろしいですか?」 => 「はい」の場合
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
// 「このアプリはプッシュ通知を送信します。よろしいですか?」 => 「いいえ」の場合
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
// ParseRestAPIでRemove投げるとか?
}
// 起動時にのpush
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[PFPush handlePush:userInfo];
// UnityにsendMessageしてよしなに
}
// 普通のpush
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))handler
{
[PFPush handlePush:userInfo];
// UnityにsendMessageしてよしなに
}
@end
IMPL_APP_CONTROLLER_SUBCLASS(TestAppController)
例ではsetApplicationIdをapplicationWillEnterForegroundに書いてますが、android側にも同じマジックコードを書く事を考えるとUnityのプラグイン側に書いた方が一元管理できると思います。
まぁandroidはParse.initializeをonCreateでしてやらないと落ちるんですけどね