- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UMSocialManager defaultManager] openLog:YES];
[[UMSocialManager defaultManager] setUmSocialAppkey:UM_APPKey];
[self configUSharePlatforms];
}
#pragma mark -- 友盟分享设置
- (void)configUSharePlatforms{
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxd5af95220867b52e" appSecret:@"fc206169c6ffc4b6dc392f81133eca9e" redirectURL:nil];
[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_Sina)]];
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1106169079" appSecret:@"7CnfJR5J2RbukmnF" redirectURL:nil];
}
- (void)shareButtonAction:(UIButton *)btn {
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
NSLog(@"platformType == %ld",(long)platformType);
[UMShareObjct shareWebPageToPlatformType:platformType ViewCoViewController:self URLDic:self.dataDic Type:1];
}];
}
#import <Foundation/Foundation.h>
#import <UMSocialCore/UMSocialCore.h>
@interface UMShareObjct : NSObject
+ (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType ViewCoViewController:(UIViewController *)viewController URLDic:(NSDictionary *)dic Type:(NSInteger)type;
+ (UIImage *) getImageFromURL:(NSString *)fileURL;
@end
#import "UMShareObjct.h"
#import "AlertCustomView.h"
@implementation UMShareObjct
+ (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType ViewCoViewController:(UIViewController *)viewController URLDic:(NSDictionary *)dic Type:(NSInteger)type{
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
NSString *thumbURL;
if(type == 1){
thumbURL = [NSString stringWithFormat:@"%@%@",ImageRequest,dic[@"img"]];
NSLog(@"tehunnn == %@",thumbURL);
}else if (type == 2){
thumbURL = [NSString stringWithFormat:@"%@%@",ImageRequest,dic[@"titlepic"]];
NSLog(@"tehunnn == %@",thumbURL);
}
UIImage *img = [UMShareObjct getImageFromURL:thumbURL];
UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:dic[@"title"] descr:dic[@"content"] thumImage:img];
shareObject.webpageUrl = dic[@"shareurl"];
messageObject.shareObject = shareObject;
[[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:viewController completion:^(id result, NSError *error) {
if (error) {
UMSocialLogInfo(@"************Share fail with error %@*********",error);
}else{
if ([result isKindOfClass:[UMSocialShareResponse class]]) {
UMSocialShareResponse *resp = result;
UMSocialLogInfo(@"response message is %@",resp.message);
UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
}else{
UMSocialLogInfo(@"response data is %@",result);
}
}
}];
}
+ (UIImage *) getImageFromURL:(NSString *)fileURL{
NSLog(@"执行图片下载函数");
UIImage * result;
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
result = [UIImage imageWithData:data];
return result;
}
@end