Unity iOS打包之覆写UnityAppController.mm

参考文章:https://blog.csdn.net/huanguuuu1234567/article/details/78027207

在 Unity 插件目录下创建以下文件:
/path/to/unity/project/Assets/Plugins/iOS/CustomAppController.mm

参考原文中有一处修正,即是需先#import "UnityAppController.h"

下面以极光推送SDK 为例:

#import "JPUSHService.h"
#import "JPushEventCache.h"
#import 

// 如需使用广告标识符 IDFA 则添加该头文件,否则不添加。
#import 

#import "UnityAppController.h"

@interface CustomAppController : UnityAppController
@end

IMPL_APP_CONTROLLER_SUBCLASS (CustomAppController)

@implementation CustomAppController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  [[JPushEventCache sharedInstance] handFinishLaunchOption:launchOptions];
  /*
    不使用 IDFA 启动 SDK。
参数说明:
    appKey: 极光官网控制台应用标识。
    channel: 频道,暂无可填任意。
    apsForProduction: YES: 发布环境;NO: 开发环境。
  */
  [JPUSHService setupWithOption:launchOptions appKey:@"b8213ec93d03ff11a560f516" channel:@"" apsForProduction:NO];

  return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  // Required.
  [JPUSHService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  // Required.
  [[JPushEventCache sharedInstance] sendEvent:userInfo withKey:@"JPushPluginReceiveNotification"];
  [JPUSHService handleRemoteNotification:userInfo];
}

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo     fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {
  [[JPushEventCache sharedInstance] sendEvent:userInfo withKey:@"JPushPluginReceiveNotification"];
}

@end

你可能感兴趣的:(Unity iOS打包之覆写UnityAppController.mm)