ios QQ分享

QQ分享 需要配置的和微信[微信分享]http://m.itdecent.cn/p/0225b32c8f1a大同小異 這里 就直接截圖了

  • 導(dǎo)入SDK
    TencentOpenAPI.framework TencentOpenApi_iOS_Bundle.bundle


    導(dǎo)入SDK .png
  • 添加依賴庫
    (記得16年第一次做 QQ分享的時候 參考的文檔添加的依賴庫,最后什么都配置好了,卻一直分享不了。。流程檢測了好幾遍都沒問題,也沒有任何報(bào)錯。。。。 無奈與官方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”。


添加依賴庫.png
  • 添加白名單以及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];
    }
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容