簡潔SDK

//  AppDelegate.m
//  簡潔SDK12-25
//
//  Created by dc004 on 15/12/25.
//  Copyright © 2015年 gang. All rights reserved.
//

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

//騰訊開放平臺(對應QQ和QQ空間)SDK頭文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>

//微信SDK頭文件
#import "WXApi.h"

//新浪微博SDK頭文件
#import "WeiboSDK.h"
//新浪微博SDK須要在項目Build Settings中的Other Linker Flags添加"-ObjC"

//人人SDK頭文件
#import <RennSDK/RennSDK.h>



@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    /**
     *  設置ShareSDK的appKey,若是還沒有在ShareSDK官網註冊過App,請移步到http://mob.com/login 登陸後臺進行應用註冊,
     *  在將生成的AppKey傳入到此方法中。
     *  方法中的第二個第三個參數爲須要鏈接社交平臺SDK時觸發,
     *  在此事件中寫入鏈接代碼。第四個參數則爲配置本地社交平臺時觸發,根據返回的平臺類型來配置平臺信息。
     *  若是您使用的時服務端託管平臺信息時,第2、四項參數能夠傳入nil,第三項參數則根據服務端託管平臺來決定要鏈接的社交SDK。
     */
    //SDK密鑰
    [ShareSDK registerApp:@"dd6883245838"
     
          activePlatforms:@[
                            @(SSDKPlatformTypeSinaWeibo),
                        
                          
                      
                            @(SSDKPlatformTypeRenren),
                           ]
                 onImport:^(SSDKPlatformType platformType)
     {
         
         //跳轉APP用此方法
//         switch (platformType)
//         {
//             case SSDKPlatformTypeWechat:
//                 [ShareSDKConnector connectWeChat:[WXApi class]];
//                 break;
//             case SSDKPlatformTypeQQ:
//                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
//                 break;
//             case SSDKPlatformTypeSinaWeibo:
//                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];
//                 break;
//             case SSDKPlatformTypeRenren:
//                 [ShareSDKConnector connectRenren:[RennClient class]];
//                 break;
//                default:
//                 break;
//         }
     }
          onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
     {
         
         switch (platformType)
         {
             case SSDKPlatformTypeSinaWeibo:
                 //設置新浪微博應用信息,其中authType設置爲使用SSO+Web形式受權
                 [appInfo SSDKSetupSinaWeiboByAppKey:@"568898243"
                                           appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                                         redirectUri:@"http://www.sharesdk.cn"
                                            authType:SSDKAuthTypeBoth];
                 break;
//             case SSDKPlatformTypeWechat:
//                 [appInfo SSDKSetupWeChatByAppId:@"wx4868b35061f87885"
//                                       appSecret:@"64020361b8ec4c99936c0e3999a9f249"];
//                 break;
//             case SSDKPlatformTypeQQ:
//                 [appInfo SSDKSetupQQByAppId:@"100371282"
//                                      appKey:@"aed9b0303e3ed1e27bae87c33761161d"
//                                    authType:SSDKAuthTypeBoth];
//                 break;
             case SSDKPlatformTypeRenren:
                 [appInfo        SSDKSetupRenRenByAppId:@"226427"
                                                 appKey:@"fc5b8aed373c4c27a05b712acba0f8c3"
                                              secretKey:@"f29df781abdd4f49beca5a2194676ca4"
                                               authType:SSDKAuthTypeBoth];
                 break;
//             case SSDKPlatformTypeGooglePlus:
//                 [appInfo SSDKSetupGooglePlusByClientID:@"232554794995.apps.googleusercontent.com"
//                                           clientSecret:@"PEdFgtrMw97aCvf0joQj7EMk"
//                                            redirectUri:@"http://localhost"
//                                               authType:SSDKAuthTypeBoth];
//                 break;
             default:
                 break;
         }
     }];    return YES;
}






//  ViewController.m
//  簡潔SDK12-25
//
//  Created by dc004 on 15/12/25.
//  Copyright © 2015年 gang. All rights reserved.
//

#import "ViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
@interface ViewController ()
{
    UIButton *button;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    button = [[UIButton alloc]initWithFrame:CGRectMake(160, 25, 37.5, 30)];
    [button setTitle:@"按鈕" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithRed:0 green:1 blue:1 alpha:0.8] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(butt) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}
-(void)butt{
    //一、建立分享參數
    NSArray* imageArray = @[[UIImage imageNamed:@"shareImg.png"]];
    //(注意:圖片必需要在Xcode左邊目錄裏面,名稱必需要傳正確,若是要分享網絡圖片,能夠這樣傳iamge參數 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"])
    if (imageArray) {
        
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"分享內容"
                                         images:imageArray
                                            url:[NSURL URLWithString:@"http://mob.com"]
                                          title:@"分享標題"
                                           type:SSDKContentTypeAuto];
        //二、分享(能夠彈出咱們的分享菜單和編輯界面)
        [ShareSDK showShareActionSheet:nil //要顯示菜單的視圖, iPad版中此參數做爲彈出菜單的參照視圖,只有傳這個才能夠彈出咱們的分享菜單,能夠傳分享的按鈕對象或者本身建立小的view 對象,iPhone能夠傳nil不會影響
                                 items:nil
                           shareParams:shareParams
                   onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                       
                       switch (state) {
                           case SSDKResponseStateSuccess:
                           {
                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                                   message:nil
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"肯定"
                                                                         otherButtonTitles:nil];
                               [alertView show];
                               break;
                           }
                           case SSDKResponseStateFail:
                           {
                               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失敗"
                                                                               message:[NSString stringWithFormat:@"%@",error]
                                                                              delegate:nil
                                                                     cancelButtonTitle:@"OK"
                                                                     otherButtonTitles:nil, nil];
                               [alert show];
                               break;
                           }
                           default:
                               break;
                       }
                   }
         ];}
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
相關文章
相關標籤/搜索