1.集成友盟分享,需要先注册一个友盟账号,注册地址
友盟sdk下载地址友盟sdk下载地址
2,成功下载sdk集成后,微信分享需要配置一下
新浪微博 之类到同样配置就行
3.整合完之后就开始上代码了
ShareManage.h
//
// ShareManage.h
// KONKA_MARKET
//
// Created by wxxu on 14/12/18.
// Copyright (c) 2014年 archon. All rights reserved.
// 分享管理
// 友盟APIKey
#define UMeng_APIKey @""//友盟appKey
#define WX_APP_KEY @""//微信appId
#define WX_APP_SECRET @""//微信appSecret
#define share_title @""//分享标题
#define share_content @""//分享内容
#define share_url @""//分享url
#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>
@interface ShareManage : NSObject <MFMessageComposeViewControllerDelegate>
+ (ShareManage *)shareManage;- (void)shareConfig;/**微信分享**/
- (void)wxShareWithViewControll:(UIViewController *)viewC;/**新浪微博分享**/- (void)wbShareWithViewControll:(UIViewController *)viewC;/**微信朋友圈分享**/- (void)wxpyqShareWithViewControll:(UIViewController *)viewC;/**短信分享**/- (void)smsShareWithViewControll:(UIViewController *)viewC;@end
ShareManage.m
//
// ShareManage.m
// KONKA_MARKET
//
// Created by wxxu on 14/12/18.
// Copyright (c) 2014年 archon. All rights reserved.
// 分享管理
#import "ShareManage.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "WXApi.h"
@implementation ShareManage {
UIViewController *_viewC;
}
static ShareManage *shareManage;
+ (ShareManage *)shareManage
{
@synchronized(self)
{
if (shareManage == nil) {
shareManage = [[self alloc] init];
}
return shareManage;
}
}
#pragma mark 注册友盟分享微信
- (void)shareConfig
{
//设置友盟社会化组件appkey
[UMSocialData setAppKey:UMeng_APIKey];
[UMSocialData openLog:YES];
//注册微信
[WXApi registerApp:WX_APP_KEY];
//设置图文分享
[UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
}
#pragma mark 微信分享
- (void)wxShareWithViewControll:(UIViewController *)viewC
{
_viewC = viewC;
[[UMSocialControllerService defaultControllerService] setShareText:share_content shareImage:nil socialUIDelegate:nil];
[UMSocialWechatHandler setWXAppId:WX_APP_KEY appSecret:WX_APP_SECRET url:share_url];
[UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession].snsClickHandler(viewC,[UMSocialControllerService defaultControllerService],YES);
}
#pragma mark 新浪微博分享
- (void)wbShareWithViewControll:(UIViewController *)viewC
{
_viewC = viewC;
[[UMSocialControllerService defaultControllerService] setShareText:share_content shareImage:nil socialUIDelegate:nil];
[UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(viewC,[UMSocialControllerService defaultControllerService],YES);
}
#pragma mark 微信朋友圈分享
- (void)wxpyqShareWithViewControll:(UIViewController *)viewC
{
_viewC = viewC;
[[UMSocialControllerService defaultControllerService] setShareText:share_content shareImage:nil socialUIDelegate:nil];
[UMSocialWechatHandler setWXAppId:WX_APP_KEY appSecret:WX_APP_SECRET url:share_url];
[UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(viewC,[UMSocialControllerService defaultControllerService],YES);
}
#pragma mark 短信分享
- (void)smsShareWithViewControll:(UIViewController *)viewC
{
_viewC = viewC;
Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
if (messageClass != nil) {
if ([messageClass canSendText]) {
[self displaySMSComposerSheet];
}
else {
//@"设备没有短信功能"
}
}
else {
//@"iOS版本过低,iOS4.0以上才支持程序内发送短信"
}
}
#pragma mark 短信的代理方法
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[_viewC dismissViewControllerAnimated:YES completion:nil];
switch (result)
{
case MessageComposeResultCancelled:
break;
case MessageComposeResultSent:
//@"感谢您的分享!"
break;
case MessageComposeResultFailed:
break;
default:
break;
}
}
- (void)displaySMSComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = self;
picker.navigationBar.tintColor = [UIColor blackColor];
// picker.recipients = [NSArray arrayWithObject:@"10086"];
picker.body = share_content;
[_viewC presentViewController:picker animated:YES completion:nil];
}
@end