首先是快速集成ShareSDK(这里我就直接复制官方文档)
一、获取AppKey
二、下载SDK
三、快速集成
第一步:将下载的SDK解压后导入您的工程中,见下图(点击这里查看视频教程)
拖到工程中后弹出以下对话框,勾选”Copy items into destination group’s folder(if needed)”,并点击“Finish“按钮, 如图
注意:请务必在上述步骤中选择“Create groups for any added folders”单选按钮组。如果你选择“Create folder references for any added folders”,一个蓝色的文件夹引用将被添加到项目并且将无法找到它的资源。
第二步:添加依赖库(点击这里查看视频教程)
添加步骤见下图
必须添加的依赖库如下:
- SystemConfiguration.framework
- QuartzCore.framework
- CoreTelephony.framework
- libicucore.dylib
- libz.1.2.5.dylib
- Security.framework
#import "AppDelegate.h"
#import "mainViewController.h"
#import <ShareSDK/ShareSDK.h>
#import "WXApi.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
//填写mob开发者帐号添加APP时,获得的AppKey
[ShareSDKregisterApp:@"iosv1101"];
//微信登陆的时候需要初始化.注册网址http://open.weixin.qq.com->获得AppId、appSecret
[ShareSDKconnectWeChatWithAppId:@"wx4868b35061f87885"
appSecret:@"64020361b8ec4c99936c0e3999a9f249"
wechatCls:[WXApiclass]];
mainViewController *main=[[mainViewControlleralloc]init];
[self.windowsetRootViewController:main];
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
return YES;
}
//当用户通过其它应用启动本应用时,会回调这个方法,url参数是其它应用调用openURL:方法时传过来的
- (BOOL)application: (UIApplication *)application handleOpenURL: (NSURL *)url
{
return [ShareSDKhandleOpenURL:url
wxDelegate:self];
}
//当用户通过其它应用启动本应用时,会回调这个方法,url参数是其它应用调用openURL:方法时传过来的
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation
{
return [ShareSDKhandleOpenURL: url
sourceApplication:sourceApplication
annotation: annotation
wxDelegate:self];
}
添加实现代码
#import "mainViewController.h"
#import <ShareSDK/ShareSDK.h>
@interface mainViewController ()
@end
@implementation mainViewController
- (void)viewDidLoad {
[superviewDidLoad];
UIButton *button=[UIButtonbuttonWithType:UIButtonTypeCustom];
[buttonsetFrame:CGRectMake(100,100,100,30)];
[button setTitle:@"登陆微信"forState:UIControlStateNormal];
[button setTitleColor:[UIColorblueColor]forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(buttonCLick:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
// Do any additional setup after loading the view.
}
-(void)buttonCLick:(UIButton *)button{
[ShareSDKgetUserInfoWithType:ShareTypeWeixiSession
authOptions:nil
result:^(BOOL result,id<ISSPlatformUser> userInfo,id<ICMErrorInfo> error) {
if (result)
{
//打印输出用户uid:
NSLog(@"uid = %@",[userInfouid]);
//打印输出用户昵称:
NSLog(@"name = %@",[userInfonickname]);
//打印输出用户头像地址:
NSLog(@"icon = %@",[userInfoprofileImage]);
NSLog(@"用户信息= %@",[userInfosourceData]);
id<ISSPlatformCredential> credential = [ShareSDKgetCredentialWithType:ShareTypeWeixiSession];
NSLog(@"uid = %@ token = %@",[credentialuid],[credentialtoken]);
}
else
{
NSLog(@"失败!error code == %d, error code == %@", [errorerrorCode], [errorerrorDescription]);
}
}];
}
注意
1.在此之前要配置url schemes 值为你申请的微信AppId
2.如果编译#import<ShareSDK/ShareSDK.h>报错,说找不到,就要在Build Setting那边添加你的FrameWork Search Paths(特别是你导入ShareSDK后删掉,又导入就会报这种错误)
这是网盘的事例代码
链接: http://pan.baidu.com/s/1kTorpZp 密码: 89zc