封装qq分享静态库到cocopod
1,创建framework库,到腾讯开放平台(open.qq.com)申请项目appid
2,将iOS SDK中的TencentOpenAPI.framework和TencentOpenApi_IOS_Bundle.bundle文件拷贝到应用开发的目录下并引用。
3,添加SDK依赖的系统库文件。分别是”Security.framework”, “libiconv.dylib”,“SystemConfiguration.framework”,“CoreGraphics.Framework”、“libsqlite3.dylib”、“CoreTelephony.framework”、“libstdc++.dylib”、“libz.dylib”。
4,创建一个继承与NSObject的类,例如:CHShareUtil,测试方法:- (void)share;
在Build Phases中把.h文件放进public里。在静态库头文件里引入#import “CHQQShare.h"
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/QQApiInterfaceObject.h>
#import <TencentOpenAPI/TencentOAuth.h>
- (void)share
{
TencentOAuth*oauth = [[TencentOAuth alloc] initWithAppId:@“你的id,必须填写才能分享" andDelegate:self];
QQApiTextObject *txtObj = [QQApiTextObject objectWithText:@"text"];
SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:txtObj];
QQApiSendResultCode sent = [QQApiInterface sendReq:req];
}
5,创建一个项目,引用自己封装的framework,注意:在Build Rules里创建(如果没有)Copy Files,Destination选Frameworks,把自定义的framework拖过来。否则会出现崩溃:Reason: image not found。
6,在项目plist里面配置白名单
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>weixin</string>
<string>mqq</string>
<string>tim</string>
<string>wechat</string>
<string>mqqopensdkapiv2</string>
<string>mqqapi</string>
</array>
</plist>
7, 项目里调用: [[[CHQQShare alloc]init] share]; 即可实现qq分享
8,最后根据我的pod博客即可发布到pod。http://www.cnblogs.com/huntaiji/p/6908982.html
遇到找不到头文件QQApiInterface.h的问题,pod配置文件的问题,参考我的这俩主要配置:
s.source_files = "CHShareUtil", "CHShareUtil/**/*.{h,m}"
s.public_header_files = "CHShareUtil/CHQQShare.h"
全配置文件:
Pod::Spec.new do |s|
s.name = "CHShareUtil"
s.version = "0.0.3"
s.summary = "封装QQ分享到cocoaPod,无需复杂配置即可方便的调用,基于:qq V3.2.1"
s.description = <<-DESC
封装QQ分享到cocoaPod,无需复杂配置即可方便的调用,基于:qq V3.2.1 后期会集成微信等分享功能
DESC
s.homepage = "https://github.com/lichanghong/CHShareUtil"
s.license = "MIT"
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
s.author = { "李长鸿" => "lichanghong@b.360.cn" }
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/lichanghong/CHShareUtil", :tag => "#{s.version}" }
s.source_files = "CHShareUtil", "CHShareUtil/**/*.{h,m}"
s.public_header_files = "CHShareUtil/CHQQShare.h"
s.resource = "CHShareUtil/TencentOpenApi_IOS_Bundle.bundle"
s.requires_arc = true
s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' }
s.frameworks = 'Security','SystemConfiguration','CoreGraphics','CoreTelephony', 'UIKit', 'Foundation'
s.libraries = 'iconv','sqlite3','stdc++','z'
s.ios.vendored_frameworks = 'CHShareUtil/TencentOpenAPI.framework'
end