IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。

(1)官方下载ShareSDK iOS 2.8.8,地址:

(2)根据实际情况,引入相关的库,参考。

(3)在项目的AppDelegate中一般情况下有三个操作,第一是注册ShareSDK,第二是注册各个平台的账号,第三是关于微信等应用的回调处理。

//// AppDelegate.m// ShareSDKTest//// Created by wangdalei on 14-6-23.// Copyright (c) 2014年 王大雷. All rights reserved.//#import "AppDelegate.h"#import "RootViewController.h"#import <ShareSDK/ShareSDK.h>#import "WeiboApi.h"#import <TencentOpenAPI/QQApiInterface.h>#import <TencentOpenAPI/TencentOAuth.h>#import "WXApi.h"#import <TencentOpenAPI/QQApiInterface.h>#import <TencentOpenAPI/TencentOAuth.h>@implementation AppDelegate@synthesize rootVC;- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];if (self.rootVC==nil) {self.rootVC = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:nil];}UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:self.rootVC];self.window.rootViewController = rootNav;self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyAndVisible];<span style="color:#ff0000;">[ShareSDK registerApp:@"1a2e7ab5fb6c"];</span><span style="color:#3366ff;"> //添加新浪微博应用 注册网址 wdl@pmmq.com 此处需要替换成自己应用的[ShareSDK connectSinaWeiboWithAppKey:@"3201194191"appSecret:@"0334252914651e8f76bad63337b3b78f"redirectUri:@""];//添加腾讯微博应用 注册网址 wdl@pmmq.com 此处需要替换成自己应用的[ShareSDK connectTencentWeiboWithAppKey:@"801307650"appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"redirectUri:@""wbApiCls:[WeiboApi class]];//添加QQ空间应用 注册网址 wdl@pmmq.com 此处需要替换成自己应用的[ShareSDK connectQZoneWithAppKey:@"100371282"appSecret:@"aed9b0303e3ed1e27bae87c33761161d"qqApiInterfaceCls:[QQApiInterface class]tencentOAuthCls:[TencentOAuth class]];//此参数为申请的微信AppID wdl@pmmq.com 此处需要替换成自己应用的[ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885" wechatCls:[WXApi class]];//添加QQ应用 该参数填入申请的QQ AppId wdl@pmmq.com 此处需要替换成自己应用的[ShareSDK connectQQWithQZoneAppKey:@"100371282"qqApiInterfaceCls:[QQApiInterface class]tencentOAuthCls:[TencentOAuth class]];</span>return YES;}- (void)applicationWillResignActive:(UIApplication *)application {// 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.// 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.}- (void)applicationDidEnterBackground:(UIApplication *)application {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application {// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application {// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}<span style="color:#ff6600;">#pragma mark – WX回调- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {return [ShareSDK handleOpenURL:url wxDelegate:self];}- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];}#pragma mark – WXApiDelegate/*! @brief 收到一个来自微信的请求,,第三方应用程序处理完后调用sendResp向微信发送结果 * * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 * @param req 具体请求内容,是自动释放的 */-(void) onReq:(BaseReq*)req{}/*! @brief 发送一个sendReq后,收到微信的回应 * * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 * @param resp具体的回应内容,是自动释放的 */-(void) onResp:(BaseResp*)resp{}</span>@end午餐,晚餐。或许吃得不好,可是却依旧为对方擦去嘴角的油渍。

IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。

相关文章:

你感兴趣的文章:

标签云: