QQ分享 需要配置的和微信[微信分享]http://www.reibang.com/p/0225b32c8f1a大同小異 這里 就直接截圖了
-
導(dǎo)入SDK
TencentOpenAPI.framework TencentOpenApi_iOS_Bundle.bundle
導(dǎo)入SDK .png 添加依賴庫
(記得16年第一次做 QQ分享的時候 參考的文檔添加的依賴庫浅辙,最后什么都配置好了拍霜,卻一直分享不了查邢。钩蚊。流程檢測了好幾遍都沒問題梢夯,也沒有任何報錯俗或。括丁。。乌助。 無奈與官方Demo 對比 才發(fā)現(xiàn)文檔上少寫了幾個庫。陌知。他托。。仆葡。不過 赏参,最近看 好像文檔已經(jīng)補(bǔ)全了。沿盅。把篓。。腰涧。盡管文檔還是很亂韧掩。。盡管官方Demo還是運(yùn)行不了窖铡。疗锐。。费彼。滑臊。)
添加SDK依賴的系統(tǒng)庫文件。分別是”Security.framework”, “l(fā)ibiconv.dylib”箍铲,“SystemConfiguration.framework”雇卷,“CoreGraphics.Framework”、“l(fā)ibsqlite3.dylib”颠猴、“CoreTelephony.framework”关划、“l(fā)ibstdc++.dylib”、“l(fā)ibz.dylib”翘瓮。
-
添加白名單以及URL scheme
QQ與QQ空間白名單:mqzoneopensdk贮折、mqzoneopensdkapi、mqzoneopensdkapi19春畔、mqzoneopensdkapiV2脱货、mqqOpensdkSSoLogin、mqqopensdkapiV2律姨、mqqopensdkapiV3振峻、wtloginmqq2、mqqapi择份、mqqwpa扣孟、mqzone、mqq荣赶。
白名單.png
F4E0224D-DF0B-4096-9870-18317BEF1683.png 注冊并實(shí)現(xiàn)方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//注意: 初始化授權(quán) 開發(fā)者需要在這里填入自己申請到的 AppID
_oauth = [[TencentOAuth alloc] initWithAppId:__TencentDemoAppid__ andDelegate:self];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{ NSString *path = [url absoluteString];
if ([self.qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {
[self.qqDelegate shareSuccssWithQQCode:[[path substringWithRange:NSMakeRange([path rangeOfString:@"&error="].location+[path rangeOfString:@"&error="].length, [path rangeOfString:@"&version"].location-[path rangeOfString:@"&error="].location)] integerValue]];
}
return [TencentOAuth HandleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [TencentOAuth HandleOpenURL:url];
}
具體實(shí)現(xiàn) (這里只記錄了其中一種分享方式 其他的參考文檔)
sendReq QQ
NSURL *url = [NSURL URLWithString:_webModel.url];
NSURL *preimageUrl = [NSURL URLWithString:_webModel.image];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:_webModel.title description:[NSString stringWithFormat:@"%@",_webModel.content] previewImageURL:preimageUrl];
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
appdelegate.qqDelegate = self;
QQApiSendResultCode sent = [QQApiInterface sendReq:req];//分享給QQ好友
[self handleSendResult:sent];
SendReqToQZone QQ空間
NSURL *url = [NSURL URLWithString:_webModel.url];
NSURL *preimageUrl = [NSURL URLWithString:_webModel.image];
QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:_webModel.title description:[NSString stringWithFormat:@"%@",_webModel.content] previewImageURL:preimageUrl];
//請求幫助類,分享的所有基礎(chǔ)對象凤价,都要封裝成這種請求對象鸽斟。
SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];
//通過自定義的qqdelegate來通知本controller,是否成功分享
appdelegate.qqDelegate = self;
QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];//分享到QQ空間
[self handleSendResult:sent];
回調(diào)
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
switch (sendResult)
{
case EQQAPIAPPNOTREGISTED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"App未注冊" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIMESSAGECONTENTINVALID:
case EQQAPIMESSAGECONTENTNULL:
case EQQAPIMESSAGETYPEINVALID:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"發(fā)送參數(shù)錯誤" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTINSTALLED:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"您的設(shè)備未安裝手機(jī)QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIQQNOTSUPPORTAPI:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"您的設(shè)備未安裝手機(jī)QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPISENDFAILD:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"發(fā)送失敗" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
case EQQAPIVERSIONNEEDUPDATE:
{
UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"當(dāng)前QQ版本太低利诺,需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
[msgbox show];
break;
}
default:
{
break;
}
}
}
#pragma mark QQ分享回調(diào)代理
/* 返回碼 對照說明
0 成功
-1 參數(shù)錯誤
-2 該群不在自己的群列表里面
-3 上傳圖片失敗
-4 用戶放棄當(dāng)前操作
-5 客戶端內(nèi)部處理錯誤
*/
-(void)shareSuccssWithQQCode:(NSInteger)code{
NSLog(@"code %ld",(long)code);
if (code == 0) {
UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"提示" message:@"分享成功" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[aler show];
}else{
UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"提示" message:@"分享失敗" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[aler show];
}
}