友盟開發者平臺官網 友盟集成文檔
友盟sdk下載地址友盟sdk下載地址
2,成功下載sdk集成後,微信分享需要配置壹下
新浪微博 之類到同樣配置就行
3.整合完之後就開始上代碼了
ShareManage.h
[objc] view plain copy
//
// 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
[objc] view plain copy
//
// 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