简体   繁体   English

如何在SWIFT Xcode中导入Rollout.io

[英]How to Import Rollout.io in SWIFT Xcode

I am trying to install rollout.io its simply it says put thus code in you ApppDelegate the problem is that it is in Objective-C. 我正在尝试安装rollout.io,它只是说它把代码放在你的ApppDelegate中,问题是它在Objective-C中。 So i used a converter to try and change it to Swift but it doesn't work when i try to put the Objective-C import header into my code. 所以我使用转换器尝试将其更改为Swift,但是当我尝试将Objective-C导入头放入我的代码时它不起作用。 Even when i try to convert it the Online converter doesn't even show the "import" part 即使我尝试转换它,在线转换器甚至不会显示“导入”部分

Ive tried these all ready 我已经准备好了这些

Code: 码:

import  Rollout
import rollout
import UIRollout

all of these fail. 所有这些都失败了。

i can get the bottom part in the swift eject but not the top"import ,Rollout/Rollout.h>" part 我可以在快速弹出中获得底部但不是顶部的“import,Rollout / Rollout.h>”部分

在此输入图像描述

在此输入图像描述

Note: 注意:

The following will allow you to setup Rollout SDK in case your AppDelegate is in Swift. 以下将允许您设置Rollout SDK,以防您的AppDelegate在Swift中。

Update: 更新:

Rollout SDK 1.1.0 has Swift interface for calling the setup, so all the following info is not relevant now. Rollout SDK 1.1.0具有用于调用设置的Swift接口,因此以下所有信息现在都不相关。

The original answer: 原答案:

1. Swift-ObjC Bridging Header 1. Swift-ObjC桥接标题

To call [Rollout setupWithDebug:] from Swift, you should have Objective-C Bridging Header set and <Rollout/Rollout.h> should be imported from it: 要从Swift调用[Rollout setupWithDebug:] ,你应该设置Objective-C Bridging Header并从中导入<Rollout/Rollout.h>

  1. In the build settings, check if SWIFT_OBJC_BRIDGING_HEADER is already set. 在构建设置中,检查是否已设置SWIFT_OBJC_BRIDGING_HEADER。 If yes, go to step 4 如果是,请转到步骤4
  2. Create a C header ( File -> New -> File... -> iOS -> Source -> Header File ). 创建一个C头( 文件 - >新建 - >文件... - > iOS - >源 - >头文件 )。 Call it somehow, eg ObjC-Bridging-Header 以某种方式调用它,例如ObjC-Bridging-Header
  3. Go to the build settings and set SWIFT_OBJC_BRIDGING_HEADER to point to the file you've created ( ObjC-Bridging-Header.h ). 转到构建设置并将SWIFT_OBJC_BRIDGING_HEADER设置为指向您创建的文件( ObjC-Bridging-Header.h )。 A relative path is required in the setting if the file is not at the project's root - more details in this SO answer 如果文件不在项目的根目录,则设置中需要相对路径 - 此SO答案中的更多详细信息
  4. Go to the header and add the import line there: 转到标题并在那里添加导入行:

    #import <Rollout/Rollout.h>

2. #if debug 2. #if debug

In order to allow Rollout testing mode (for easy hot-patches testing) it's also required to translate #ifdef Debug from ObjC . 为了允许Rollout测试模式(为了便于热补丁测试),还需要从ObjC翻译#ifdef Debug This can be done by setting OTHER_SWIFT_FLAGS in build settings like this: 这可以通过在构建设置中设置OTHER_SWIFT_FLAGS来完成,如下所示:

在此输入图像描述

3. Call setup from AppDelegate.swift 3.从AppDelegate.swift调用设置

Now you can add the following lines to application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) : 现在您可以application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)添加到application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)

    #if DEBUG
        Rollout.setupWithKey("<rollout_key>", developmentDevice: true)
    #else
        Rollout.setupWithKey("<rollout_key>", developmentDevice: false)
    #endif

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

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