很好用很便捷的shareSDK封装

//
//  ShareSDKHelper.m
//  xiaoyao
//
//  Created by xiaoyao on 14/11/16.
//  Copyright (c) 2014年 xiaoyao. All rights reserved.
//

#import "ShareSDKHelper.h"


@implementation ShareSDKHelper

+ (void)regeisterSharePlatformInAppDelegate {
  
  [ShareSDK registerApp:@"31a728a463ee"];
  // 向分享的平台注册,得到授权码 key
  [ShareSDK connectSinaWeiboWithAppKey:@"2211740027"
                             appSecret:@"cdeb63d2c0a454a929a70459d4db4a8e"
                           redirectUri:@"http://www.sharesdk.cn"];
  
  // 初始化新浪微博平台
  [ShareSDK connectSinaWeiboWithAppKey:@"2211740027"
                             appSecret:@"cdeb63d2c0a454a929a70459d4db4a8e"
                           redirectUri:@"http://www.sharesdk.cn"
                           weiboSDKCls:[WeiboSDK class]];
  
  [ShareSDK connectTencentWeiboWithAppKey:@"801307650"
                                appSecret:@"ae36f4ee3946e1cbb98d6965b0b2ff5c"
                              redirectUri:@"http://www.sharesdk.cn"
                                 wbApiCls:[WeiboApi class]];
  
  [ShareSDK connectQZoneWithAppKey:@"100371282"
                         appSecret:@"aed9b0303e3ed1e27bae87c33761161d"
                 qqApiInterfaceCls:[QQApiInterface class]
                   tencentOAuthCls:[TencentOAuth class]];
  
  [ShareSDK connectQQWithQZoneAppKey:@"100371282"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
  
  [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
                         wechatCls:[WXApi class]];
  
  [ShareSDK connectMail];
  
  [ShareSDK connectSMS];
}

+ (BOOL)handleOpenURL:(NSURL *)url {
  return [ShareSDK handleOpenURL:url wxDelegate:self];
}

+ (BOOL)handleOpenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:self];
}

+ (void)oneKeyShareWithCompletion:(ShareCompletion)completion withTitle:(NSString *)title {
  // 一键分享列表
  NSArray *oneKeyShareList = [ShareSDK getShareListWithType:ShareTypeWeixiSession,
                              ShareTypeWeixiTimeline,
                              ShareTypeSinaWeibo,
                              ShareTypeTencentWeibo, nil];
  
  // 分享视图
  id<ISSShareOptions>shareOptions = [ShareSDK defaultShareOptionsWithTitle:title
                                                           oneKeyShareList:oneKeyShareList
                                                            qqButtonHidden:NO
                                                     wxSessionButtonHidden:NO
                                                    wxTimelineButtonHidden:NO
                                                      showKeyboardOnAppear:NO
                                                         shareViewDelegate:nil
                                                       friendsViewDelegate:nil
                                                     picViewerViewDelegate:nil];
  
  NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ShareSDK" ofType:@"jpg"];
  // 构造分享内容,分享一条新闻内容
  id<ISSContent> publishContent = [ShareSDK content:@"分享内容"
                                     defaultContent:@"默认分享内容,没内容时显示"
                                              image:[ShareSDK imageWithPath:imagePath]
                                              title:@"ShareSDK"
                                                url:@"http://www.sharesdk.cn"
                                        description:@"这是一条测试信息"
                                          mediaType:SSPublishContentMediaTypeNews];
   //弹出菜单
  [ShareSDK showShareActionSheet:nil
                       shareList:nil
                         content:publishContent
                   statusBarTips:YES
                     authOptions:nil
                    shareOptions:shareOptions
                          result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                            if (state == SSResponseStateSuccess) {
                              completion(YES);
                            } else if (state == SSResponseStateFail) {
                              completion(NO);
                            }
                          }];

}


/*! @brief 发送一个sendReq后,收到微信的回应
 *
 * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。
 * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。
 * @param resp具体的回应内容,是自动释放的
 */
-(void) onResp:(BaseResp*)resp {
  
}

@end

//
//  ShareController.m
//  xiaoyao
//
//  Created by xiaoyao on 14/11/15.
//  Copyright (c) 2014年 xiaoyao. All rights reserved.
//

#import "ShareController.h"
#import <ShareSDK/ShareSDK.h>
#import <AGCommon/AGCommon.h>
#import "ShareSDKHelper.h"

@interface ShareController ()

@end

@implementation ShareController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
  CGRect fm = CGRectMake(100, 200, 80, 50);
  [shareButton setFrame:fm];
  [shareButton setTitle:@"分享" forState:UIControlStateNormal];
  [shareButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
  shareButton.titleLabel.font = [UIFont systemFontOfSize:14];
  [shareButton addTarget:self action:@selector(shareButtonClicked:)
        forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:shareButton];
}

// 注册各平台的
- (void)shareToPlatform {
  [ShareSDKHelper regeisterSharePlatformInAppDelegate];
}

- (void)shareButtonClicked:(UIButton *)shareButton {
  [ShareSDKHelper oneKeyShareWithCompletion:^(BOOL isSuccess) {
    
  } withTitle:@"分享"];
}
@end


//
//  AppDelegate.m
//  xiaoyao
//
//  Created by xiaoyao on 14/11/15.
//  Copyright (c) 2014年 xiaoyao. All rights reserved.
//

#import "AppDelegate.h"
#import "ShareController.h"
#import <ShareSDK/ShareSDK.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

  // Override point for customization after application launch.
  self.window.backgroundColor = [UIColor whiteColor];
  
  ShareController *share = [[ShareController alloc] init];
  [share shareToPlatform];
  self.window.rootViewController = share;
  [self.window makeKeyAndVisible];
  return YES;
}

- (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];
  
}

- (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:.
}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值