share分享
其他的步骤就像授权登陆一样,key、分享平台、白名单
头文件需要导入:
#import <ShareSDK/ShareSDK.h>
#import <ShareSDK/ShareSDK+Base.h>
#import <ShareSDKExtension/SSEShareHelper.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>
#import <ShareSDKUI/SSUIShareActionSheetCustomItem.h>
#import <ShareSDKExtension/ShareSDK+Extension.h>
// 点击分享按钮处理事件,调用系统的分享显示
- (void)sharesButtonClick
{
//1、创建分享参数
NSArray* imageArray = @[[UIImage imageNamed:@"u=607859702,2445450382&fm=21&gp=0"]];
// (注意:图片必须要在Xcode左边目录里面,名称必须要传正确,如果要分享网络图片,可以这样传iamge参数
images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"];
if (imageArray)// 如果有图片才进
{
/**
* 设置分享参数
*
* @param text 文本
* @param images 图片集合,传入参数可以为单张图片信息,也可以为一个NSArray,数组元素可以为UIImage、NSString(图片路径)、NSURL(图片路径)、SSDKImage。如: @"http://www.mob.com/images/logo_black.png" 或 @[@"http://www.mob.com/images/logo_black.png"]
* @param url 网页路径/应用路径
* @param title 标题
* @param type 分享类型
*/
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:@"分享内容"
images:imageArray
url:[NSURL URLWithString:@"http://www.gzpaotu.cn"]
title:@"分享标题"
type:SSDKContentTypeAuto];
//2、分享(可以弹出我们的分享菜单和编辑界面)
[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;
}
}
];}
}
这样实现就可以看到分享功能,但是全部是英文名字,然后需要修改就可以看到中文咯,但是需要手机显示中文才可以
file:///Users/mac/Library/Containers/com.tencent.qq/Data/Library/Application%20Support/QQ/793996103/Image/Image6/JNMO4%25I)~M)5K_ZB_0F%5B5I9.jpg
file:///Users/mac/Library/Containers/com.tencent.qq/Data/Library/Application%20Support/QQ/793996103/Image/Image6/B(PBFY4_HN1XSU%5BCY7SM%7DOY.jpg
自己定义一个window层,里面有个背景按钮、里面再有一个shareButtonView、里面装按钮
点击对应按钮跳转对应的分享平台
自定义分享
#pragma mark - Private Method
- (void)shareButtonClick:(SSDKPlatformType)platformType
{
NSArray* imageArray = @[[UIImage imageNamed:@"u=607859702,2445450382&fm=21&gp=0"]];
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
[shareParams SSDKSetupShareParamsByText:@"分享内容"
images:imageArray
url:[NSURL URLWithString:@"http://www.gzpaotu.cn"]
title:@"分享标题"
type:SSDKContentTypeAuto];
[ShareSDK share:platformType parameters:shareParams onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
switch (state)
{
case SSDKResponseStateBegin:
{
}
break;
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:nil
delegate:nil
cancelButtonTitle:@"好的"
otherButtonTitles:nil, nil];
[alert show];
}
break;
case SSDKResponseStateCancel:
{
}
break;
default:
break;
}
}];
}
这里提示一下,如果不适用真机测试是不会出现QQ和微信的