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 <UserNotifications/UserNotifications.h>

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

#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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容