ShareSDK分享到微信、微信朋友圈、QQ

+ (void)shareWithContent:(NSString *)content
                pngImage:(UIImage *)pngImage
                   title:(NSString *)title
                     url:(NSString *)url
               mediaType:(SSPublishContentMediaType)mediaType
       shareViewDelegate:(id)shareViewDelegate
              completion:(HYBShareCompletion)completion {
  // 定义分享列表
  NSArray *shareList = [ShareSDK customShareListWithType:
                        SHARE_TYPE_NUMBER(ShareTypeWeixiSession),
                        SHARE_TYPE_NUMBER(ShareTypeWeixiTimeline),
                        SHARE_TYPE_NUMBER(ShareTypeQQ),
                        SHARE_TYPE_NUMBER(ShareTypeQQSpace),
                        nil];

  // 分享内容
  id sharedContent = [ShareSDK content:content
                                    defaultContent:content
                                             image:[ShareSDK pngImageWithImage:pngImage]
                                             title:title
                                               url:url
                                       description:@"看不懂,就是你的错"
                                         mediaType:mediaType];
  [sharedContent addWeixinSessionUnitWithType:INHERIT_VALUE
                                       content:INHERIT_VALUE
                                         title:INHERIT_VALUE
                                           url:INHERIT_VALUE
                                    thumbImage:[ShareSDK pngImageWithImage:pngImage]
                                         image:INHERIT_VALUE
                                  musicFileUrl:nil
                                       extInfo:nil
                                      fileData:nil
                                  emoticonData:nil];

  [sharedContent addWeixinTimelineUnitWithType:[NSNumber numberWithInteger:SSPublishContentMediaTypeNews]
                                       content:INHERIT_VALUE
                                         title:content
                                           url:INHERIT_VALUE
                                    thumbImage:[ShareSDK pngImageWithImage:pngImage]
                                         image:INHERIT_VALUE
                                  musicFileUrl:nil
                                       extInfo:nil
                                      fileData:nil
                                  emoticonData:nil];
  
  [sharedContent addQQUnitWithType:INHERIT_VALUE
                           content:INHERIT_VALUE
                             title:INHERIT_VALUE
                               url:INHERIT_VALUE
                             image:INHERIT_VALUE];
  
  // 验证参数
  id authOptions = [ShareSDK authOptionsWithAutoAuth:YES
                                                       allowCallback:NO
                                                       authViewStyle:SSAuthViewStyleFullScreenPopup
                                                        viewDelegate:nil
                                             authManagerViewDelegate:nil];

  
  // 如果是使用一键分享,则需要传oneKeyShareList参数,
  // 如果使用的是自定义的分享菜单,则这个参数需要设置为nil,
  // 否则会出现
  id shareOptions = [ShareSDK defaultShareOptionsWithTitle:@"我是标哥"
                                                            oneKeyShareList:nil
                                                             qqButtonHidden:YES
                                                      wxSessionButtonHidden:YES
                                                     wxTimelineButtonHidden:YES
                                                       showKeyboardOnAppear:NO
                                                          shareViewDelegate:shareViewDelegate
                                                        friendsViewDelegate:nil
                                                      picViewerViewDelegate:nil];
  
  [ShareSDK showShareActionSheet:nil
                       shareList:shareList
                         content:sharedContent
                   statusBarTips:YES
                     authOptions:authOptions
                    shareOptions:shareOptions
                          result:^(ShareType type, SSResponseState state, id statusInfo, id error, BOOL end) {
                            NSLog(@"%d", type);
                            if (end) {
                              if (completion) {
                                completion(SSResponseStateSuccess == state);
                              }
                            }
                          }];
  return;
}

你可能感兴趣的:(ShareSDK分享到微信、微信朋友圈、QQ)