友盟+搜索

{{errorMsg}}

概述

cocos2dx 6.0是特别适配了分享6.0以上的版本,同时也方便了cocos2dx的开发者,适配之后的分享版本,相对于之前的5.0,更加简洁,方便,灵活性更强

配置ios工程

将一下文件引入ios工程内

配置分享的sdk

下载SDK最新版

将下载framework或.a文件放入umeng_ios_social_sdk文件夹中,按照分享的文档配置分享sdk

初始化sdk

分享的文档中需要在AppDelegate.m中配置的信息全部放入AppController.mm中

[UMSocialGlobal shareInstance].type = @"Cocos2d-x";
//设置友盟appkey
[[UMSocialManager defaultManager] setUmSocialAppkey:@"57b432afe0f55a9832001a0a"];

注意这个初始化的两句话一定要在最开始加入,防止出现调用的时候,还没初始化引起的错误

添加appkey

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
[[UMSocialManager defaultManager] openLog:YES];

// 获取友盟social版本号
NSLog(@"UMeng social version: %@", [UMSocialGlobal umSocialSDKVersion]);

//设置友盟appkey
[[UMSocialManager defaultManager] setUmSocialAppkey:@"57b432afe0f55a9832001a0a"];

//设置微信的appKey和appSecret
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wxdc1e388c3822c80b" appSecret:@"3baf1193c85774b3fd9d18447d76cab0" redirectURL:@"http://mobile.umeng.com/social"];
   /*
 * 添加某一平台会加入平台下所有分享渠道,如微信:好友、朋友圈、收藏,QQ:QQ和QQ空间
 * 以下接口可移除相应平台类型的分享,如微信收藏,对应类型可在枚举中查找
*/
//[[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
//设置分享到QQ互联的appID
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"100424468"/*设置QQ平台的appID*/  appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];

//设置新浪的appKey和appSecret
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3921700954"  appSecret:@"04b48b094faeb16683c32669824ebdad" redirectURL:@"http://sns.whalecloud.com/sina2/callback"];
//设置Twitter的appKey和appSecret
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Twitter appKey:@"fB5tvRpna1CKK97xZUslbxiet"  appSecret:@"YcbSvseLIwZ4hZg9YmgJPP5uWzd4zr6BpBKGZhf07zzh3oj62K" redirectURL:nil];

//设置Facebook的appKey和UrlString
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook appKey:@"506027402887373"  appSecret:nil redirectURL:@"http://www.umeng.com/social"];
// Override point for customization after application launch.

// Add the view controller's view to the window and display.
_window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

// Init the EAGLView
EAGLView *__glView = [EAGLView viewWithFrame: [_window bounds]
                                 pixelFormat: kEAGLColorFormatRGB565
                                 depthFormat: GL_DEPTH24_STENCIL8_OES
                          preserveBackbuffer: NO
                                  sharegroup: nil
                               multiSampling: NO
                             numberOfSamples: 0];

// Use RootViewController manage EAGLView 
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
viewController.view = __glView;

// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
    // warning: addSubView doesn't work on iOS6
    [_window addSubview: viewController.view];
}
else
{
    // use this method on ios6
    [_window setRootViewController:viewController];
}

[_window makeKeyAndVisible];

[[UIApplication sharedApplication] setStatusBarHidden:true];

cocos2d::CCApplication::sharedApplication()->run();

return YES;
}

同时需要增加系统回调

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
if (!result) {
    // 其他如支付等SDK的回调
}
return result;
}

自定义分享面板

在classes/ios找到UmSocialControllerIOS.mm文件找到openShareWithImagePath和openCustomShareBoard方法进行分享面板的修改 根据ios面板修改文档进行修改如下(去掉了标题和取消按钮):

[UMSocialShareUIConfig shareInstance].shareTitleViewConfig.isShow = NO;
[UMSocialShareUIConfig shareInstance].shareCancelControlConfig.isShow = NO;
[UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
    ……        
}];