//
//  CustomAppController.mm
//  Unity-iPhone
//
//  Created by os on 2025/5/25.
//

#include <UnityAppController.h>
#include <TencentOpenAPI/TencentOAuth.h>
#import "TencentQQ.h"
#import "IAPManager.h"

@interface CustomAppController : UnityAppController

@end

IMPL_APP_CONTROLLER_SUBCLASS(CustomAppController)

@implementation CustomAppController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions
{
    [super application:application didFinishLaunchingWithOptions:launchOptions];
    
    TencentQQ* tencentQQ = [TencentQQ Instance];
    [tencentQQ Init];
    IAPManager* iapManager = [IAPManager Instance];
    [iapManager Init];
    return true;
}

- (BOOL) application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    return [TencentOAuth HandleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
    if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
        NSURL *url = userActivity.webpageURL;
        if (url && [TencentOAuth CanHandleUniversalLink:url]) {
            return [TencentOAuth HandleUniversalLink:url];
        }
    }
    return YES;
}

@end
