zoukankan      html  css  js  c++  java
  • iOS开发之第三方分享QQ分享,史上最新最全第三方分享QQ方式实现

    本文章源码地址: https://github.com/zhonggaorong/QQLoginDemo

    项目搭建参考:  (包含QQ登录源码下载 、 QQ sdk集成)

    http://blog.csdn.net/zhonggaorong/article/details/51699623

    分享第三方分享之QQ分享各种坑的总结:

    1. 分享老是提示未注册QQ,解决办法就是在程序已启动,就向QQ进行授权。代码如下

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    2.     [[TencentOAuth alloc] initWithAppId:TENCENT_CONNECT_APP_KEY andDelegate:self];  
    3.     return YES;  
    4. }  

    QQ未注册错误代号 EQQAPIAPPNOTREGISTED

    2. 分享的时候, 不跳转到QQ界面,解决办法就是在openurl中,添加如下代码:

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{  
    2.     /** 
    3.      处理由手Q唤起的跳转请求 
    4.      param url 待处理的url跳转请求 
    5.      param delegate 第三方应用用于处理来至QQ请求及响应的委托对象 
    6.       eturn 跳转请求处理结果,YES表示成功处理,NO表示不支持的请求协议或处理失败 
    7.      */  
    8.     if ([url.absoluteString hasPrefix:[NSString stringWithFormat:@"tencent%@",TENCENT_CONNECT_APP_KEY]]) {  
    9.         [QQApiInterface handleOpenURL:url delegate:self];  
    10.         return [TencentOAuth HandleOpenURL:url];  
    11.     }  
    12.     return YES;  
    13. }  

    3. iOS9白名单的问题,没有吧QQ的相关白名单填完成。 完成的如下。

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. <key>LSApplicationQueriesSchemes</key>  
    2. <array>  
    3.     <string>mqqapi</string>  
    4.     <string>mqq</string>  
    5.     <string>mqqOpensdkSSoLogin</string>  
    6.     <string>mqqconnect</string>  
    7.     <string>mqqopensdkdataline</string>  
    8.     <string>mqqopensdkgrouptribeshare</string>  
    9.     <string>mqqopensdkfriend</string>  
    10.     <string>mqqopensdkapi</string>  
    11.     <string>mqqopensdkapiV2</string>  
    12.     <string>mqqopensdkapiV3</string>  
    13.     <string>mqzoneopensdk</string>  
    14.     <string>wtloginmqq</string>  
    15.     <string>wtloginmqq2</string>  
    16.     <string>mqqwpa</string>  
    17.     <string>mqzone</string>  
    18.     <string>mqzonev2</string>  
    19.     <string>mqzoneshare</string>  
    20.     <string>wtloginqzone</string>  
    21.     <string>mqzonewx</string>  
    22.     <string>mqzoneopensdkapiV2</string>  
    23.     <string>mqzoneopensdkapi19</string>  
    24.     <string>mqzoneopensdkapi</string>  
    25.     <string>mqzoneopensdk</string>  
    26. </array>  



    进入正题:

    分享的对象包含:

    QQApiTextObject     文本对象

    QQApiURLObject      URL对象类型

    QQApiExtendObject   扩展数据类型

    QQApiImageObject    图片对象

    QQApiImageArrayForQZoneObject  图片数组对象 用于分享图片到空间,走写说说路径,是一个指定为图片类型的,当图片数组为空时,默认走文本写说说

    QQApiVideoForQZoneObject      视频对象

    QQApiWebImageObject           网络图片对象

    QQApiFileObject               本地文件对象

    QQApiAudioObject              音频URL对象

    QQApiVideoObject        视频URL对象 :用于分享目标内容为视频的URL的对象

    QQApiNewsObject       新闻URL对象

    等等。

    相关的分享对象的权限看下图:

         分享的核心代码为: (分享 新闻URL对象为例子)

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. /**   
    2.      分享 新闻URL对象 。 
    3.      获取一个autorelease的<code>QQApiAudioObject</code> 
    4.      @param url 音频内容的目标URL 
    5.      @param title 分享内容的标题 
    6.      @param description 分享内容的描述 
    7.      @param previewURL 分享内容的预览图像URL 
    8.      @note 如果url为空,调用<code>QQApi#sendMessage:</code>时将返回FALSE 
    9.      */  
    10.       
    11.     NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];  
    12.     NSURL *preimageUrl = [NSURL URLWithString:@"http://www.sizzee.com/index.php/catalog/product/view/id/55730/s/10196171/?SID=au0lhpg54f11nenmrjvhsh0rq6?uk=Y3VzdG9tZXJfaWQ9Mjc0fHByb2R1Y3RfaWQ9NTU3MzA"];  
    13.     QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:@"测试分享" description:[NSString stringWithFormat:@"分享内容------新闻URL对象分享 ------test"] previewImageURL:preimageUrl];  
    14.       
    15.     //请求帮助类,分享的所有基础对象,都要封装成这种请求对象。  
    16.     SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];  
    17.     QQApiSendResultCode sent = [QQApiInterface sendReq:req];  
    18.       
    19.     //通过自定义的qqdelegate来通知本controller,是否成功分享  
    20.     appdelegate.qqDelegate = self;  
    21.       
    22.     NSLog(@"QQApiSendResultCode %d",sent);  
    23.       
    24.     [self handleSendResult:sent];  
    25.   /*  QQApiSendResultCode 说明 
    26.     EQQAPISENDSUCESS = 0,                      操作成功 
    27.     EQQAPIQQNOTINSTALLED = 1,                   没有安装QQ 
    28.     EQQAPIQQNOTSUPPORTAPI = 2, 
    29.     EQQAPIMESSAGETYPEINVALID = 3,              参数错误 
    30.     EQQAPIMESSAGECONTENTNULL = 4, 
    31.     EQQAPIMESSAGECONTENTINVALID = 5, 
    32.     EQQAPIAPPNOTREGISTED = 6,                   应用未注册 
    33.     EQQAPIAPPSHAREASYNC = 7, 
    34.     EQQAPIQQNOTSUPPORTAPI_WITH_ERRORSHOW = 8, 
    35.     EQQAPISENDFAILD = -1,                       发送失败 
    36.     //qzone分享不支持text类型分享 
    37.     EQQAPIQZONENOTSUPPORTTEXT = 10000, 
    38.     //qzone分享不支持image类型分享 
    39.     EQQAPIQZONENOTSUPPORTIMAGE = 10001, 
    40.     //当前QQ版本太低,需要更新至新版本才可以支持 
    41.     EQQAPIVERSIONNEEDUPDATE = 10002, 
    42.    */  
    43. }  
    44. - (void)handleSendResult:(QQApiSendResultCode)sendResult  
    45. {  
    46.     switch (sendResult)  
    47.     {  
    48.         case EQQAPIAPPNOTREGISTED:  
    49.         {  
    50.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    51.             [msgbox show];  
    52.               
    53.               
    54.             break;  
    55.         }  
    56.         case EQQAPIMESSAGECONTENTINVALID:  
    57.         case EQQAPIMESSAGECONTENTNULL:  
    58.         case EQQAPIMESSAGETYPEINVALID:  
    59.         {  
    60.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    61.             [msgbox show];  
    62.               
    63.               
    64.             break;  
    65.         }  
    66.         case EQQAPIQQNOTINSTALLED:  
    67.         {  
    68.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    69.             [msgbox show];  
    70.               
    71.               
    72.             break;  
    73.         }  
    74.         case EQQAPIQQNOTSUPPORTAPI:  
    75.         {  
    76.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    77.             [msgbox show];  
    78.               
    79.               
    80.             break;  
    81.         }  
    82.         case EQQAPISENDFAILD:  
    83.         {  
    84.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    85.             [msgbox show];  
    86.               
    87.               
    88.             break;  
    89.         }  
    90.         case EQQAPIVERSIONNEEDUPDATE:  
    91.         {  
    92.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    93.             [msgbox show];  
    94.             break;  
    95.         }  
    96.         default:  
    97.         {  
    98.             break;  
    99.         }  
    100.     }  
    101. }  

    上面提到了分享。那么如何来监听分享是否成功呢。这就要回到我们的appdelegate里面。监听 

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. - (void)onResp:(QQBaseResp *)resp  


    appdelegate中的相关代码如下:

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. **  
    2.  处理来至QQ的响应  
    3.  */  
    4. - (void)onResp:(QQBaseResp *)resp{  
    5.      NSLog(@" ----resp %@",resp);  
    6.       
    7.     // SendMessageToQQResp应答帮助类  
    8.     if ([resp.class isSubclassOfClass: [SendMessageToQQResp class]]) {  //QQ分享回应  
    9.         if (_qqDelegate) {  
    10.             if ([_qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {  
    11.                 SendMessageToQQResp *msg = (SendMessageToQQResp *)resp;  
    12.                 NSLog(@"code %@  errorDescription %@  infoType %@",resp.result,resp.errorDescription,resp.extendInfo);  
    13.                 [_qqDelegate shareSuccssWithQQCode:[msg.result integerValue]];  
    14.             }  
    15.         }  
    16.     }  
    17. }  



    完整的代码如下

    appdelegate.h

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. //  
    2. //  AppDelegate.h  
    3. //  QQLoginDemo  
    4. //  
    5. //  Created by 张国荣 on 16/6/17.  
    6. //  Copyright © 2016年 BateOrganization. All rights reserved.  
    7. //  
    8.   
    9. #import <UIKit/UIKit.h>  
    10.   
    11. @protocol QQShareDelegate <NSObject>  
    12.   
    13. -(void)shareSuccssWithQQCode:(NSInteger)code;  
    14. @end  
    15.   
    16. @interface AppDelegate : UIResponder <UIApplicationDelegate>  
    17.   
    18. @property (strong, nonatomic) UIWindow *window;  
    19. @property (weak  , nonatomic) id<QQShareDelegate> qqDelegate;  
    20.   
    21. @end  

    appdelegate,m

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. //  
    2. //  AppDelegate.m  
    3. //  QQLoginDemo  
    4. //  
    5. //  Created by 张国荣 on 16/6/17.  
    6. //  Copyright © 2016年 BateOrganization. All rights reserved.  
    7. //  
    8.   
    9. #import "AppDelegate.h"  
    10. #import <TencentOpenAPI/QQApiInterface.h>  
    11. #import <TencentOpenAPI/TencentOAuth.h>  
    12. #define TENCENT_CONNECT_APP_KEY @"app id"  
    13. @interface AppDelegate ()<QQApiInterfaceDelegate,TencentSessionDelegate>  
    14.   
    15. @end  
    16.   
    17. @implementation AppDelegate  
    18.   
    19.   
    20. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    21.     // Override point for customization after application launch.  
    22.       
    23. //    [QQApiInterface ]  
    24.       
    25.     [[TencentOAuth alloc] initWithAppId:TENCENT_CONNECT_APP_KEY andDelegate:self];  
    26. //    NSLog(@"%@",oauth.appId);  
    27.     return YES;  
    28. }  
    29.   
    30. - (void)applicationWillResignActive:(UIApplication *)application {  
    31.     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.  
    32.     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.  
    33. }  
    34.   
    35.   
    36.   
    37. -(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{  
    38.     /** 
    39.      处理由手Q唤起的跳转请求 
    40.      param url 待处理的url跳转请求 
    41.      param delegate 第三方应用用于处理来至QQ请求及响应的委托对象 
    42.       eturn 跳转请求处理结果,YES表示成功处理,NO表示不支持的请求协议或处理失败 
    43.      */  
    44.     if ([url.absoluteString hasPrefix:[NSString stringWithFormat:@"tencent%@",TENCENT_CONNECT_APP_KEY]]) {  
    45.         [QQApiInterface handleOpenURL:url delegate:self];  
    46.         return [TencentOAuth HandleOpenURL:url];  
    47.           
    48.     }  
    49.     return YES;  
    50. }  
    51.   
    52. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{  
    53.     /** 
    54.      处理由手Q唤起的跳转请求 
    55.      param url 待处理的url跳转请求 
    56.      param delegate 第三方应用用于处理来至QQ请求及响应的委托对象 
    57.       eturn 跳转请求处理结果,YES表示成功处理,NO表示不支持的请求协议或处理失败 
    58.      */  
    59.     if ([url.absoluteString hasPrefix:[NSString stringWithFormat:@"tencent%@",TENCENT_CONNECT_APP_KEY]]) {  
    60.          [QQApiInterface handleOpenURL:url delegate:self];  
    61.         return [TencentOAuth HandleOpenURL:url];  
    62.           
    63.     }  
    64.     return YES;  
    65. }  
    66. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{  
    67.     /** 
    68.      处理由手Q唤起的跳转请求 
    69.      param url 待处理的url跳转请求 
    70.      param delegate 第三方应用用于处理来至QQ请求及响应的委托对象 
    71.       eturn 跳转请求处理结果,YES表示成功处理,NO表示不支持的请求协议或处理失败 
    72.      */  
    73.     if ([url.absoluteString hasPrefix:[NSString stringWithFormat:@"tencent%@",TENCENT_CONNECT_APP_KEY]]) {  
    74.         [QQApiInterface handleOpenURL:url delegate:self];  
    75.         return [TencentOAuth HandleOpenURL:url];  
    76.     }  
    77.     return YES;  
    78. }  
    79. /** 
    80.  处理来至QQ的请求 
    81.  */  
    82. - (void)onReq:(QQBaseReq *)req{  
    83.     NSLog(@" ----req %@",req);  
    84. }  
    85.   
    86. /** 
    87.  处理来至QQ的响应 
    88.  */  
    89. - (void)onResp:(QQBaseResp *)resp{  
    90.      NSLog(@" ----resp %@",resp);  
    91.       
    92.     // SendMessageToQQResp应答帮助类  
    93.     if ([resp.class isSubclassOfClass: [SendMessageToQQResp class]]) {  //QQ分享回应  
    94.         if (_qqDelegate) {  
    95.             if ([_qqDelegate respondsToSelector:@selector(shareSuccssWithQQCode:)]) {  
    96.                 SendMessageToQQResp *msg = (SendMessageToQQResp *)resp;  
    97.                 NSLog(@"code %@  errorDescription %@  infoType %@",resp.result,resp.errorDescription,resp.extendInfo);  
    98.                 [_qqDelegate shareSuccssWithQQCode:[msg.result integerValue]];  
    99.             }  
    100.         }  
    101.     }  
    102. }  
    103.   
    104. /** 
    105.  处理QQ在线状态的回调 
    106.  */  
    107. - (void)isOnlineResponse:(NSDictionary *)response{  
    108.   
    109. }  
    110.   
    111.   
    112. @end  

    viewcontroller.h

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. #import <UIKit/UIKit.h>  
    2.   
    3. @interface ViewController : UIViewController  
    4.   
    5.   
    6. @end  

    viewcontroller.m

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. #import "ViewController.h"  
    2. #import <TencentOpenAPI/TencentOAuth.h>  
    3. #import <TencentOpenAPI/TencentApiInterface.h>  
    4. #import <TencentOpenAPI/QQApiInterfaceObject.h>  
    5. #import <TencentOpenAPI/QQApiInterface.h>  
    6. #import "AppDelegate.h"  
    7.   
    8. #define APP_ID @"app id"  
    9. @interface ViewController ()<TencentSessionDelegate,QQShareDelegate>  
    10. {  
    11.     TencentOAuth *_tencentOAuth;  
    12.     NSMutableArray *_permissionArray;   //权限列表  
    13.     AppDelegate *appdelegate;  
    14. }  
    15. @end  
    16.   
    17. @implementation ViewController  
    18.   
    19. - (void)viewDidLoad {  
    20.     [super viewDidLoad];  
    21.     appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;  
    22.     self.view.backgroundColor = [UIColor whiteColor];  
    23. }  
    24.   
    25. #pragma mark QQ登录  
    26. - (IBAction)loginAction:(id)sender {  
    27.     _tencentOAuth=[[TencentOAuth alloc]initWithAppId:APP_ID andDelegate:self];  
    28.       
    29.     //设置权限数据 , 具体的权限名,在sdkdef.h 文件中查看。  
    30.     _permissionArray = [NSMutableArray arrayWithObjects: kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,nil];  
    31.       
    32.     //登录操作  
    33.     [_tencentOAuth authorize:_permissionArray inSafari:NO];  
    34. }  
    35.   
    36. /** 
    37.  * 登录成功后的回调 
    38.  */  
    39. - (void)tencentDidLogin{  
    40.       
    41.     /** Access Token凭证,用于后续访问各开放接口 */  
    42.     if (_tencentOAuth.accessToken) {  
    43.           
    44.         //获取用户信息。 调用这个方法后,qq的sdk会自动调用  
    45.         //- (void)getUserInfoResponse:(APIResponse*) response  
    46.         //这个方法就是 用户信息的回调方法。  
    47.           
    48.         [_tencentOAuth getUserInfo];  
    49.     }else{  
    50.       
    51.         NSLog(@"accessToken 没有获取成功");  
    52.     }  
    53.       
    54. }  
    55.   
    56. /** 
    57.  * 登录失败后的回调 
    58.  * param cancelled 代表用户是否主动退出登录 
    59.  */  
    60. - (void)tencentDidNotLogin:(BOOL)cancelled{  
    61.     if (cancelled) {  
    62.         NSLog(@" 用户点击取消按键,主动退出登录");  
    63.     }else{  
    64.         NSLog(@"其他原因, 导致登录失败");  
    65.     }  
    66. }  
    67.   
    68. /** 
    69.  * 登录时网络有问题的回调 
    70.  */  
    71. - (void)tencentDidNotNetWork{  
    72.     NSLog(@"没有网络了, 怎么登录成功呢");  
    73. }  
    74.   
    75.   
    76. /** 
    77.  * 因用户未授予相应权限而需要执行增量授权。在用户调用某个api接口时,如果服务器返回操作未被授权,则触发该回调协议接口,由第三方决定是否跳转到增量授权页面,让用户重新授权。 
    78.  * param tencentOAuth 登录授权对象。 
    79.  * param permissions 需增量授权的权限列表。 
    80.  *  eturn 是否仍然回调返回原始的api请求结果。 
    81.  *  ote 不实现该协议接口则默认为不开启增量授权流程。若需要增量授权请调用 ef TencentOAuth#incrAuthWithPermissions:  注意:增量授权时用户可能会修改登录的帐号 
    82.  */  
    83. - (BOOL)tencentNeedPerformIncrAuth:(TencentOAuth *)tencentOAuth withPermissions:(NSArray *)permissions{  
    84.       
    85.     // incrAuthWithPermissions是增量授权时需要调用的登录接口  
    86.     // permissions是需要增量授权的权限列表  
    87.     [tencentOAuth incrAuthWithPermissions:permissions];  
    88.     return NO; // 返回NO表明不需要再回传未授权API接口的原始请求结果;  
    89.     // 否则可以返回YES  
    90. }  
    91.   
    92. /** 
    93.  * [该逻辑未实现]因token失效而需要执行重新登录授权。在用户调用某个api接口时,如果服务器返回token失效,则触发该回调协议接口,由第三方决定是否跳转到登录授权页面,让用户重新授权。 
    94.  * param tencentOAuth 登录授权对象。 
    95.  *  eturn 是否仍然回调返回原始的api请求结果。 
    96.  *  ote 不实现该协议接口则默认为不开启重新登录授权流程。若需要重新登录授权请调用 ef TencentOAuth#reauthorizeWithPermissions:  注意:重新登录授权时用户可能会修改登录的帐号 
    97.  */  
    98. - (BOOL)tencentNeedPerformReAuth:(TencentOAuth *)tencentOAuth{  
    99.     return YES;  
    100. }  
    101.   
    102. /** 
    103.  * 用户通过增量授权流程重新授权登录,token及有效期限等信息已被更新。 
    104.  * param tencentOAuth token及有效期限等信息更新后的授权实例对象 
    105.  *  ote 第三方应用需更新已保存的token及有效期限等信息。 
    106.  */  
    107. - (void)tencentDidUpdate:(TencentOAuth *)tencentOAuth{  
    108.     NSLog(@"增量授权完成");  
    109.     if (tencentOAuth.accessToken  
    110.         && 0 != [tencentOAuth.accessToken length])  
    111.     { // 在这里第三方应用需要更新自己维护的token及有效期限等信息  
    112.         // **务必在这里检查用户的openid是否有变更,变更需重新拉取用户的资料等信息** _labelAccessToken.text = tencentOAuth.accessToken;  
    113.     }  
    114.     else  
    115.     {  
    116.         NSLog(@"增量授权不成功,没有获取accesstoken");  
    117.     }  
    118.   
    119. }  
    120.   
    121. /** 
    122.  * 用户增量授权过程中因取消或网络问题导致授权失败 
    123.  * param reason 授权失败原因,具体失败原因参见sdkdef.h文件中 ef UpdateFailType 
    124.  */  
    125. - (void)tencentFailedUpdate:(UpdateFailType)reason{  
    126.       
    127.     switch (reason)  
    128.     {  
    129.         case kUpdateFailNetwork:  
    130.         {  
    131.             //            _labelTitle.text=@"增量授权失败,无网络连接,请设置网络";  
    132.             NSLog(@"增量授权失败,无网络连接,请设置网络");  
    133.             break;  
    134.         }  
    135.         case kUpdateFailUserCancel:  
    136.         {  
    137.             //            _labelTitle.text=@"增量授权失败,用户取消授权";  
    138.             NSLog(@"增量授权失败,用户取消授权");  
    139.             break;  
    140.         }  
    141.         case kUpdateFailUnknown:  
    142.         default:  
    143.         {  
    144.             NSLog(@"增量授权失败,未知错误");  
    145.             break;  
    146.         }  
    147.     }  
    148.   
    149.       
    150. }  
    151.   
    152. #pragma mark 登录成功后,回调 - 返回对应QQ的相关信息  
    153. /** 
    154.  * 获取用户个人信息回调 
    155.  * param response API返回结果,具体定义参见sdkdef.h文件中 ef APIResponse 
    156.  *  emarks 正确返回示例: snippet example/getUserInfoResponse.exp success 
    157.  *          错误返回示例: snippet example/getUserInfoResponse.exp fail 
    158.  */  
    159. - (void)getUserInfoResponse:(APIResponse*) response{  
    160.       
    161.     //这里 与自己服务器进行对接,看怎么利用这获取到的个人信息。  
    162.       
    163.     NSDictionary *dic = response.jsonResponse;  
    164.     NSLog(@" response %@",dic);  
    165.       
    166.       
    167. }  
    168.   
    169. #pragma mark QQ分享  
    170. - (IBAction)QQshareAction:(id)sender {  
    171.     /**   
    172.      分享 新闻URL对象 。 
    173.      获取一个autorelease的<code>QQApiAudioObject</code> 
    174.      @param url 音频内容的目标URL 
    175.      @param title 分享内容的标题 
    176.      @param description 分享内容的描述 
    177.      @param previewURL 分享内容的预览图像URL 
    178.      @note 如果url为空,调用<code>QQApi#sendMessage:</code>时将返回FALSE 
    179.      */  
    180.       
    181.     NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];  
    182.     NSURL *preimageUrl = [NSURL URLWithString:@"http://www.sizzee.com/index.php/catalog/product/view/id/55730/s/10196171/?SID=au0lhpg54f11nenmrjvhsh0rq6?uk=Y3VzdG9tZXJfaWQ9Mjc0fHByb2R1Y3RfaWQ9NTU3MzA"];  
    183.     QQApiNewsObject* img = [QQApiNewsObject objectWithURL:url title:@"测试分享" description:[NSString stringWithFormat:@"分享内容------新闻URL对象分享 ------test"] previewImageURL:preimageUrl];  
    184.       
    185.     //请求帮助类,分享的所有基础对象,都要封装成这种请求对象。  
    186.     SendMessageToQQReq* req = [SendMessageToQQReq reqWithContent:img];  
    187.     QQApiSendResultCode sent = [QQApiInterface sendReq:req];  
    188.       
    189.     //通过自定义的qqdelegate来通知本controller,是否成功分享  
    190.     appdelegate.qqDelegate = self;  
    191.       
    192.     NSLog(@"QQApiSendResultCode %d",sent);  
    193.       
    194.     [self handleSendResult:sent];  
    195.   /*  QQApiSendResultCode 说明 
    196.     EQQAPISENDSUCESS = 0,                      操作成功 
    197.     EQQAPIQQNOTINSTALLED = 1,                   没有安装QQ 
    198.     EQQAPIQQNOTSUPPORTAPI = 2, 
    199.     EQQAPIMESSAGETYPEINVALID = 3,              参数错误 
    200.     EQQAPIMESSAGECONTENTNULL = 4, 
    201.     EQQAPIMESSAGECONTENTINVALID = 5, 
    202.     EQQAPIAPPNOTREGISTED = 6,                   应用未注册 
    203.     EQQAPIAPPSHAREASYNC = 7, 
    204.     EQQAPIQQNOTSUPPORTAPI_WITH_ERRORSHOW = 8, 
    205.     EQQAPISENDFAILD = -1,                       发送失败 
    206.     //qzone分享不支持text类型分享 
    207.     EQQAPIQZONENOTSUPPORTTEXT = 10000, 
    208.     //qzone分享不支持image类型分享 
    209.     EQQAPIQZONENOTSUPPORTIMAGE = 10001, 
    210.     //当前QQ版本太低,需要更新至新版本才可以支持 
    211.     EQQAPIVERSIONNEEDUPDATE = 10002, 
    212.    */  
    213. }  
    214. - (void)handleSendResult:(QQApiSendResultCode)sendResult  
    215. {  
    216.     switch (sendResult)  
    217.     {  
    218.         case EQQAPIAPPNOTREGISTED:  
    219.         {  
    220.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    221.             [msgbox show];  
    222.               
    223.               
    224.             break;  
    225.         }  
    226.         case EQQAPIMESSAGECONTENTINVALID:  
    227.         case EQQAPIMESSAGECONTENTNULL:  
    228.         case EQQAPIMESSAGETYPEINVALID:  
    229.         {  
    230.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    231.             [msgbox show];  
    232.               
    233.               
    234.             break;  
    235.         }  
    236.         case EQQAPIQQNOTINSTALLED:  
    237.         {  
    238.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手Q" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    239.             [msgbox show];  
    240.               
    241.               
    242.             break;  
    243.         }  
    244.         case EQQAPIQQNOTSUPPORTAPI:  
    245.         {  
    246.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    247.             [msgbox show];  
    248.               
    249.               
    250.             break;  
    251.         }  
    252.         case EQQAPISENDFAILD:  
    253.         {  
    254.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    255.             [msgbox show];  
    256.               
    257.               
    258.             break;  
    259.         }  
    260.         case EQQAPIVERSIONNEEDUPDATE:  
    261.         {  
    262.             UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"当前QQ版本太低,需要更新" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];  
    263.             [msgbox show];  
    264.             break;  
    265.         }  
    266.         default:  
    267.         {  
    268.             break;  
    269.         }  
    270.     }  
    271. }  
    272.   
    273. #pragma mark QQ分享回调代理  
    274. /* 返回码 对照说明 
    275.  0   成功 
    276.  -1  参数错误 
    277.  -2  该群不在自己的群列表里面 
    278.  -3  上传图片失败 
    279.  -4  用户放弃当前操作 
    280.  -5  客户端内部处理错误 
    281.  */  
    282. -(void)shareSuccssWithQQCode:(NSInteger)code{  
    283.     NSLog(@"code %ld",(long)code);  
    284.     if (code == 0) {  
    285.         UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"警告" message:@"分享成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil];  
    286.         [aler show];  
    287.     }else{  
    288.         UIAlertView *aler = [[UIAlertView alloc]initWithTitle:@"警告" message:@"分享失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil nil];  
    289.         [aler show];  
    290.     }  
    291. }  
    292.   
    293.   
    294. - (void)didReceiveMemoryWarning {  
    295.     [super didReceiveMemoryWarning];  
    296.     // Dispose of any resources that can be recreated.  
    297. }  
    298.   
    299. @end  




    大功告成。 

  • 相关阅读:
    scrapy 项目搭建
    linux mysql -- ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid)
    linux 安装python 和pip
    转 Pycharm及python安装详细教程
    mysql在linux下的安装
    easyui datagrid动态修改editor时动态绑定combobox的数据
    easyui combobox 在datagrid中动态加载数据
    linux 安装tomcat
    CUBRID学习笔记23 关键字列表
    CUBRID学习笔记 22 插入数据
  • 原文地址:https://www.cnblogs.com/Hakim/p/5736935.html
Copyright © 2011-2022 走看看