首先要在qq和微信开发者平台申请key才可以用,qq的key我们这里用qq123456789。微信的key我们用wx12345679
下载微信和qq开发者中心的类库在appdelegate.h文件中导入
#import "WXApi.h"
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/TencentApiInterface.h>
#import "sdkCall.h"
然后在appdelegate.m文件中的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中给微信注册
//向微信注册
[WXApi registerApp:@"wxd930ea5d5a258f4f"];
再加上下面这两个方法
#pragma mark-分享到微信分享到QQ
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
//return [WXApi handleOpenURL:url delegate:self];
return [WXApi handleOpenURL:url delegate:self]||[TencentOAuth HandleOpenURL:url] || [QQApiInterface handleOpenURL:url delegate:[sdkCall getinstance]];
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
//return [WXApi handleOpenURL:url delegate:self];
return [WXApi handleOpenURL:url delegate:self]||[TencentOAuth HandleOpenURL:url] || [QQApiInterface handleOpenURL:url delegate:[sdkCall getinstance]];
}
最后在你要实现的页面中调用以下方法
//调用微信
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.text = @"使用微信分享给你";
req.bText = YES;
req.scene = WXSceneSession;
[WXApi sendReq:req];
-(BOOL)sendReq:(BaseReq*)req
{
return YES;
}
-(void)onReq:(BaseReq *)req
{
NSLog(@"onReq:(BaseReq *)req");
}
-(void)onResp:(BaseResp *)resp
{
NSLog(@"onResp:(BaseResp *)resp");
}
//调用qq
TCAddShareDic *params = [TCAddShareDic dictionary];
params.paramTitle = [NSString stringWithFormat:@"我的qq空间分享"];
params.paramComment = [NSString stringWithFormat:@"看我厉害吧"];
params.paramSummary = [NSString stringWithFormat:@"正在做qq空间分享这个工能"];
params.paramUrl = [NSString stringWithFormat:@"www.qq.com"];
if(![[[sdkCall getinstance] oauth] addShareWithParams:params])
{
[self showInvalidTokenOrOpenIDMessage];
}else{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"系统提示" message:@"分享成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
- (void)showInvalidTokenOrOpenIDMessage
{
NSArray* permissions = [NSArray arrayWithObjects:
kOPEN_PERMISSION_GET_USER_INFO,
kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
kOPEN_PERMISSION_ADD_ALBUM,
kOPEN_PERMISSION_ADD_IDOL,
kOPEN_PERMISSION_ADD_ONE_BLOG,
kOPEN_PERMISSION_ADD_PIC_T,
kOPEN_PERMISSION_ADD_SHARE,
kOPEN_PERMISSION_ADD_TOPIC,
kOPEN_PERMISSION_CHECK_PAGE_FANS,
kOPEN_PERMISSION_DEL_IDOL,
kOPEN_PERMISSION_DEL_T,
kOPEN_PERMISSION_GET_FANSLIST,
kOPEN_PERMISSION_GET_IDOLLIST,
kOPEN_PERMISSION_GET_INFO,
kOPEN_PERMISSION_GET_OTHER_INFO,
kOPEN_PERMISSION_GET_REPOST_LIST,
kOPEN_PERMISSION_LIST_ALBUM,
kOPEN_PERMISSION_UPLOAD_PIC,
kOPEN_PERMISSION_GET_VIP_INFO,
kOPEN_PERMISSION_GET_VIP_RICH_INFO,
kOPEN_PERMISSION_GET_INTIMATE_FRIENDS_WEIBO,
kOPEN_PERMISSION_MATCH_NICK_TIPS_WEIBO,
//微云的api权限
@"upload_pic",
@"download_pic",
@"get_pic_list",
@"delete_pic",
@"upload_pic",
@"download_pic",
@"get_pic_list",
@"delete_pic",
@"get_pic_thumb",
@"upload_music",
@"download_music",
@"get_music_list",
@"delete_music",
@"upload_video",
@"download_video",
@"get_video_list",
@"delete_video",
@"upload_photo",
@"download_photo",
@"get_photo_list",
@"delete_photo",
@"get_photo_thumb",
@"check_record",
@"create_record",
@"delete_record",
@"get_record",
@"modify_record",
@"query_all_record",
nil];
[[[sdkCall getinstance] oauth] authorize:permissions inSafari:NO];
}