Swift集成第三方QQ分享错误总结
现在开发iOS程序,基本都用swift来编写代码。但是很多第三方库都是oc构建的,因此集成第三方SDK的时候,多多少少会遇到一些问题。下面是我集成QQ分享遇到的问题总结。 Xcode6是这样的。 2、新建的swift工程中并没有Frameworks文件夹。所以我们新建一个文件夹Frameworks。 3、在xxx(你的项目名)-Bridging-Header.h中添加以下头文件。路径一定要对,否则是没有效果的。我一开时就犯路径错误。这样swift才能轻松调用QQ的接口。 //TencentOpenapi
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/QQApiInterfaceObject.h>
#import <TencentOpenAPI/sdkdef.h>
#import <TencentOpenAPI/TencentMessageObject.h>
#import <TencentOpenAPI/TencentOAuthObject.h>
#import <TencentOpenAPI/WeiBoAPI.h>
#import <TencentOpenAPI/WeiyunAPI.h>
4、重写AppDelegate.swift的两个方法,用swift写。 func application(application: UIApplication,openURL url: NSURL,sourceApplication: String?,annotation: AnyObject?) -> Bool {
return TencentOAuth.HandleOpenURL(url)
}
func application(application: UIApplication,handleOpenURL url: NSURL) -> Bool {
return TencentOAuth.HandleOpenURL(url)
}
5、测试分享代码。 let title = deal["title"] as! String
let previewImageUrl = deal["image"] as! String
var newObj = QQApiNewsObject(URL: NSURL(string:"http://www.baidu.com")!,title: title,description: title,previewImageURL: NSURL(string: previewImageUrl)!,targetContentType:QQApiURLTargetTypeNews)
var req = SendMessageToQQReq(content: newObj)
QQApiInterface.sendReq(req)
基本上第三方的调用方法都差不多。对于初学者来讲,还是有点作用的。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |