简体   繁体   English

如何将appDelegate.m(Objective-C)中的内容导入到Swift项目中?

[英]How do you import something in appDelegate.m(Objective-C) into a Swift project?

I wrote an iOS app in Swift, then it is required by my company for my project to import one of Alibaba's SDK, which is written in Objective-C. 我用Swift编写了一个iOS应用,然后我的公司要求我的项目导入用Objective-C编写的阿里巴巴SDK之一。 There's a doc about how to do it in Chinese. 一个中文文档

In the demo, it seems all codes needed for the SDK to run is written in appDelegate.m in Obj-C. 在演示中,似乎要运行SDK所需的所有代码都写在Obj-C的appDelegate.m中。 I've read about Obj-C/Swift bridging header and stuff, but I don't know how to make it work for this case. 我已经读过关于Obj-C / Swift桥接头和东西的信息,但是我不知道如何使它适用于这种情况。

I can't imagine having 2 version of appDelegate in one app, how should I do it? 我无法想象一个应用程序中有2个版本的appDelegate,我该怎么办?

By the way, this is the code they expect me to copy paste into AppDelegate.m: 顺便说一句,这是他们希望我将粘贴复制到AppDelegate.m中的代码:

[[ALBBSDK sharedInstance] setDebugLogOpen:YES];
[[ALBBSDK sharedInstance] setUseTaobaoNativeDetail:NO];
[[ALBBSDK sharedInstance] setViewType:ALBB_ITEM_VIEWTYPE_TAOBAO];
[[ALBBSDK sharedInstance] setISVCode:@"my_isv_code"];

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    MainViewController *mainViewController = [[MainViewController alloc]init];
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:mainViewController];
    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options 
{     
    BOOL isHandledByALBBSDK=[[ALBBSDK sharedInstance] handleOpenURL:url];
    BOOL isHandledByALBBSDK=[[ALBBSDK sharedInstance] handleOpenURL:url];
    return YES;
}

So basically, I translate every Obj-C code into Swift and put everything into AppDelegate.swift. 因此,基本上,我将每个Obj-C代码都转换为Swift,并将所有内容都放入AppDelegate.swift。 It is easy than I thought with auto completion, and it works just fine. 使用自动完成功能比我想象的要容易,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM