【问题标题】:Integrating Intercom into Swift iOS app将对讲集成到 Swift iOS 应用程序中
【发布时间】:2015-12-09 11:12:19
【问题描述】:

我正在尝试在我正在构建的 Swift 应用程序中使用 Intercom iOS SDK。但是,他们所有的文档都是用 Objective-C 编写的。由于我刚刚开始,我不太确定如何在我的应用程序中实现对讲机。

我已将“pod 'Intercom'”添加到我的 Podfile 中,并将导入语句添加到我的桥接头中。

在 iOS 应用程序中设置对讲机的下一步是在我的应用程序 AppDelegate 中使用以下代码对其进行初始化:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize Intercom
[Intercom setApiKey:@"<#ios_sdk-...#>" forAppId:@"<#your-app-id#>"];
}

然后在我的快速视图控制器中使用 Objective-c 代码,如下所示:

- (void)successfulLogin { 
...
// Registering with Intercom is easy. For best results, use a unique user_id if you have one.
[Intercom registerUserWithUserId:@"<#123456#>"];
}

如何在我的 swift 项目中实现这样的 Objective-c 代码?

我已经四处搜索,也联系了对讲机的支持,但还没有找到答案。

非常感谢!

【问题讨论】:

    标签: ios objective-c swift intercom intercom-ios


    【解决方案1】:
    [Intercom setApiKey:@"<#ios_sdk-...#>" forAppId:@"<#your-app-id#>"];
    

    变成

    Intercom.setApiKey("<#ios_sdk-...#>", forAppId:"<#your-app-id#>")
    

    [Intercom registerUserWithUserId:@"<#123456#>"];
    

    变成

    Intercom.registerUserWithUserId("<#123456#>")
    

    我建议查看 Swift 教程以了解语法并学习如何正确地将 Objective-C 代码迁移到 Swift 代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2016-08-26
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      相关资源
      最近更新 更多