|
// |
|
// WeiboShare.m |
|
// Unity-iPhone |
|
// |
|
// Created by Sophos Zhang on 6/25/13. |
|
// |
|
// |
|
|
|
#import "WeiboShare.h" |
|
|
|
@implementation WeiboShare |
|
bool initilized = false; |
|
+ (void)InitilizePlat{ |
|
NSLog(@"initializing"); |
|
[ShareSDK registerApp:@""]; // add your ShareSDK APPkey here |
|
[ShareSDK ssoEnabled:NO]; |
|
|
|
// sina weibo |
|
[ShareSDK connectSinaWeiboWithAppKey:@"" //add your weibo appkey here |
|
appSecret:@"" // |
|
redirectUri:@""]; // |
|
initilized = true; |
|
} |
|
|
|
CGImageRef UIGetScreenImage(void); |
|
|
|
+ (void)Share:(const char*)rawJson { |
|
if(!initilized){ |
|
[self InitilizePlat]; |
|
} |
|
|
|
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8); |
|
NSString *sv = [[NSString alloc] initWithCString:rawJson encoding:enc]; |
|
NSString *sourceString = [[NSString alloc] initWithFormat:@"\357\273\277%@", sv]; // add bom |
|
UIImage* img = [self imageWithScreenContents]; |
|
//构造分享内容 |
|
id<ISSContent> publishContent = [ShareSDK content: sv //@"weibotest]" |
|
defaultContent:@"DefaultContent" |
|
image: [ShareSDK pngImageWithImage: img] |
|
title:@"ShareSDK" |
|
url:@"http://www.sharesdk.cn" |
|
description:@"这是一条测试信息" |
|
|
|
mediaType:SSPublishContentMediaTypeNews]; |
|
|
|
|
|
NSLog(@"string 内容: %@", sourceString); |
|
[ShareSDK shareContent:publishContent |
|
type:ShareTypeSinaWeibo |
|
authOptions:nil//authOptions |
|
statusBarTips:YES |
|
result:^(ShareType type, SSPublishContentState state, id<ISSStatusInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) { |
|
if (state == SSPublishContentStateSuccess) |
|
{ |
|
UnitySendMessage("-ShareManager", "ShowResult", "成功发送!"); |
|
NSLog(@"发表成功"); |
|
} |
|
else if (state == SSPublishContentStateFail) |
|
{ |
|
NSLog(@"发布失败!error code == %d, error code == %@", [error errorCode], [error errorDescription]); |
|
} |
|
}]; |
|
|
|
|
|
[sv release]; |
|
[sourceString release]; |
|
} |
|
|
|
+ (UIImage *)imageWithScreenContents |
|
{ |
|
CGImageRef cgScreen = UIGetScreenImage(); |
|
if (cgScreen) { |
|
UIImage *result = [UIImage imageWithCGImage:cgScreen]; |
|
CGImageRelease(cgScreen); |
|
return result; |
|
} |
|
return nil; |
|
} |
|
|
|
|
|
// bindng from unity |
|
|
|
void _WeiboShare(const char* rawJson) { |
|
[WeiboShare Share:rawJson]; |
|
} |
|
@end |