Google Plus和Swift中的CocoaPods [英] Google plus with CocoaPods in Swift

查看:62
本文介绍了Google Plus和Swift中的CocoaPods的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的iOS应用中,我需要添加Google+登录功能。该应用程序是在Swift中开发的。

In an iOS app I'm developing, I need to add Google+ sign-in feature. The app is developed in Swift.

我通过CocoaPods添加了GooglePlus iOS SDK。请注意,我安装了CocoaPods v0.36 beta版,该版本正式支持Swift。以前,我已经以这种方式将许多Objective-C库与Swift项目集成在一起。

I added the GooglePlus iOS SDK through CocoaPods. Please note that I have CocoaPods v0.36 beta installed which officially supports Swift. I've integrated many Objective-C libraries with Swift projects this way before.

吊舱安装成功。然后,我需要将框架导入到要使用其方法的文件中,因此我在文件顶部添加了以下几行。

The pod installation was successful. Then I needed to import the framework to files where I wanted to use its methods so I added the below lines to the top of the file.

import GooglePlus
import GoogleOpenSource

但是在构建项目时,我得到以下内容错误。

But when I build the project I get the following errors.

没有这样的模块'GooglePlus'

没有这样的模块模块 GoogleOpenSource

我在这里做错了什么?我要指定正确的名称吗?

What am I doing wrong here? Am I specifying the correct names?

编辑:我知道使用桥接标头。但是最新的CocoaPods支持将Obj-C库添加到项目中。它会自动将它们转换为框架,以便您可以快速使用它们。之前,我已经使用其他一些没有桥接标头的Obj-C库完成了此操作。使用Google+的iOS SDK失败。

I'm aware of using the bridging header. But the latest CocoaPods supports adding Obj-C libraries to projects. It automatically converts them to frameworks so that you could use them the Swift way. I've done it before with some other Obj-C libraries without the bridging header. It fails with Google+'s iOS SDK.

推荐答案

您需要创建一个桥接标头,您将在其中导入Objective-C您想向Swift公开的类。您可以在此处上查看文档。 >。

You'll need to create a bridging header where you'll import the Objective-C classes that you want to expose to Swift. You can see the documentation on how this works here.

最简单的创建方法是在项目中创建一个Objective-C类。然后Xcode会询问您是否要创建一个桥接标头,只需说是,然后删除您创建的类即可。

The easiest way to create one is to create a Objective-C class in your project. Then Xcode will ask if you'd like to create a bridging header, just say Yes and then delete the class you created.

在此标头中导入必要的Google框架,那么您将可以在Swift中访问这些类。

In this header import the necessary Google frameworks, then you'll have access to those classes in Swift.

这篇关于Google Plus和Swift中的CocoaPods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆