首页 > 代码库 > ShareSDK使用

ShareSDK使用

//appDelegate

// ShareSDK

    [ShareSDKregisterApp:AppKey_ShareSDK];

    

    // 新浪微博

    [ShareSDKconnectSinaWeiboWithAppKey:AppKey_SinaWeibo

                               appSecret:AppSecret_SinaWeibo

                             redirectUri:RedirectUri_SinaWeibo];

#pragma mark - ShareSDK回调方法 (必须写, 否则无法监控"新浪微博,腾讯微博,微信客户端"分享成功或失败的状态)

- (BOOL)application:(UIApplication *)application

      handleOpenURL:(NSURL *)url

{

    return [ShareSDKhandleOpenURL:url

                        wxDelegate:self];

}

 

- (BOOL)application:(UIApplication *)application

            openURL:(NSURL *)url

  sourceApplication:(NSString *)sourceApplication

         annotation:(id)annotation

{

    return [ShareSDKhandleOpenURL:url

                 sourceApplication:sourceApplication

                        annotation:annotation

                        wxDelegate:self];

}

 

 

// controller

// 分享核心代码!!

- (void)share:(ShareType)shareType

{

    // 1. 开启网页授权开关(仅用于QQ空间)

    if (shareType == ShareTypeQQSpace) {

//        id<ISSQZoneApp> app =(id<ISSQZoneApp>)[ShareSDK getClientWithType:ShareTypeQQSpace];

//        [app setIsAllowWebAuthorize:YES];

    }

    

    // 2. 创建分享内容

    id<ISSContent> publishContent = [ShareSDKcontent:Share_Content

                                       defaultContent:nil

                                                image:nil

                                                title:nil

                                                  url:nil

                                          description:nil

                                            mediaType:SSPublishContentMediaTypeText];

    

    // 3. 创建弹出菜单容器

    id<ISSContainer> container = [ShareSDKcontainer];

    [container setIPhoneContainerWithViewController:self];

    

    // 4. 自定义第三方登录界面的弹出样式, 并隐藏"Powered by ShareSDK"

    id<ISSAuthOptions> authOptions = [ShareSDKauthOptionsWithAutoAuth:YES

                                                         allowCallback:YES

                                                         authViewStyle:2

                                                          viewDelegate:nil

                                               authManagerViewDelegate:nil];

    [authOptions setPowerByHidden:YES];

    

    // 5. 显示分享菜单

    [ShareSDKshowShareViewWithType:shareType

                          container:container

                            content:publishContent

                      statusBarTips:YES

                        authOptions:authOptions

                       shareOptions:nil

                             result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {

                                 

                                 if (state == SSPublishContentStateBegan)

                                 {

                                     // 开始分享 -------------------------------

                                     // 弹出"正在分享"的菊花

                                     [selfshowSharingHUDWithType:type];

                                     

                                     // 发送"开始分享的通知

                                     [[NSNotificationCenterdefaultCenter] postNotificationName:Notification_Share_Beginobject:nil];

                                 }

                                 elseif (state == SSPublishContentStateCancel)

                                 {

                                     // 取消分享 -------------------------------

                                 }

                                 elseif (state == SSPublishContentStateSuccess)

                                 {

                                     // 分享成功 -------------------------------

                                     // 弹出"分享成功"的菊花

                                     [selfshowShareSuccessHUDWithType:type];

                                 }

                                 elseif (state == SSPublishContentStateFail)

                                 {

                                     // 分享失败 -------------------------------

                                     // 弹出"分享失败"的菊花

                                     [selfshowShareFailedHUDWithType:type error:error];

                                 }

                             }];

}

ShareSDK使用