├── Example ├── AppDelegate+UMeng.h ├── AppDelegate+UMeng.m ├── AppDelegate.h ├── AppDelegate.m └── util.js ├── README.md ├── UMengManager.h └── UMengManager.m /Example/AppDelegate+UMeng.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate+UMeng.h 3 | // awesomeMobile 4 | // 5 | // Created by 陈光远 on 16/1/26. 6 | // Copyright © 2016年 Facebook. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "UMSocial.h" 11 | #define UmengAppkey @"your umeng key" 12 | @interface AppDelegate (UMeng) 13 | -(void)registerUMeng; 14 | @end 15 | -------------------------------------------------------------------------------- /Example/AppDelegate+UMeng.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate+UMeng.m 3 | // awesomeMobile 4 | // 5 | // Created by 陈光远 on 16/1/26. 6 | // Copyright © 2016年 Facebook. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate+UMeng.h" 10 | 11 | #import "UMSocialWechatHandler.h" 12 | #import "MobClick.h" 13 | 14 | 15 | @implementation AppDelegate (UMeng) 16 | 17 | - (void)registerUMeng 18 | { 19 | //设置友盟社会化组件appkey 20 | [UMSocialData setAppKey:UmengAppkey]; 21 | 22 | //打开调试log的开关 23 | // [UMSocialData openLog:YES]; 24 | 25 | //设置微信AppId,设置分享url,默认使用友盟的网址 26 | [UMSocialWechatHandler setWXAppId:@"your wexin apid" appSecret:@"your weixin app secret key" url:@"url stuff"]; 27 | 28 | 29 | // 对未安装客户端平台进行隐藏 30 | [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToWechatSession,UMShareToWechatTimeline]]; 31 | 32 | //使用友盟统计 33 | [MobClick startWithAppkey:UmengAppkey reportPolicy:BATCH channelId:nil]; 34 | 35 | NSLog(@"-------registerUMeng"); 36 | } 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | #import "RCTRootView.h" 12 | 13 | 14 | @interface AppDelegate : UIResponder 15 | 16 | @property (nonatomic, strong) UIWindow *window; 17 | @property (nonatomic) RCTRootView *rootView; 18 | 19 | - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import "RCTRootView.h" 13 | #import "AppDelegate+UMeng.h" 14 | 15 | @interface AppDelegate () 16 | 17 | @end 18 | 19 | @implementation AppDelegate 20 | 21 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 22 | { 23 | 24 | //注册umeng 25 | [self registerUMeng]; 26 | 27 | 28 | //react native js bundle file 29 | NSURL *jsCodeLocation; 30 | 31 | // jsCodeLocation = [NSURL URLWithString:@"http://192.168.1.119:8081/index.ios.bundle?platform=ios&dev=true"]; 32 | 33 | jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 34 | 35 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 36 | moduleName:@"awesomeMobile" 37 | initialProperties:nil 38 | launchOptions:launchOptions]; 39 | self.rootView = rootView; 40 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 41 | UIViewController *rootViewController = [[UIViewController alloc] init]; 42 | rootViewController.view = rootView; 43 | self.window.rootViewController = rootViewController; 44 | [self.window makeKeyAndVisible]; 45 | 46 | 47 | return YES; 48 | } 49 | 50 | 51 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 52 | sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 53 | { 54 | [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil]; 55 | return [RCTLinkingManager application:application openURL:url 56 | sourceApplication:sourceApplication annotation:annotation]; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Example/util.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import NativeModules from 'react-native'; 3 | 4 | 5 | var UMengManager = NativeModules.UMengManager; 6 | 7 | module.exports = { 8 | wechatSessionShare: function(data, callback){//分享到微信 9 | UMengManager.wechatSessionShare(data, callback); 10 | }, 11 | presentSnsIconSheetView: function(data, callback){//默认分享,包括微信,微博,短信,邮箱 12 | UMengManager.presentSnsIconSheetView(data, callback); 13 | }, 14 | logPage: function(page){//记录页面加载 15 | UMengManager.logPage(page); 16 | }, 17 | endLogPageView: function(page){//记录页面退出 18 | UMengManager.endLogPageView(page); 19 | }, 20 | logEvent: function(event, data){//记录事件 21 | UMengManager.logEvent(event, data); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-umeng 2 | umeng share and analytics stuff 3 | 4 | 5 | 6 | 使用方式参看example代码 7 | 8 | dive in & have fun 9 | 10 | author: 503802922 [scott chen](http://www.classical1988.com/) 11 | 12 | mail: cgyqqcgy@gmail.com 13 | -------------------------------------------------------------------------------- /UMengManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // UMengManager.h 3 | // awesomeMobile 4 | // 5 | // Created by 陈光远 on 16/1/26. 6 | // Copyright © 2016年 Facebook. All rights reserved. 7 | // 8 | 9 | #ifndef UMengManager_h 10 | #define UMengManager_h 11 | 12 | #import "RCTBridgeModule.h" 13 | #import "UMSocial.h" 14 | #import "MobClick.h" 15 | #define UmengAppkey @"UmengAppkey" 16 | 17 | @interface UMengManager : NSObject 18 | @property (nonatomic, strong) RCTResponseSenderBlock callback; 19 | -(void) shareToSns:(NSDictionary *)aData callback:(RCTResponseSenderBlock)callback; 20 | -(void) postSNSWithTypes:(NSArray *) type params:(NSDictionary *)params callback:(RCTResponseSenderBlock)callback; 21 | @end 22 | 23 | #endif /* UMengManager_h */ 24 | -------------------------------------------------------------------------------- /UMengManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // UMengManager.m 3 | // awesomeMobile 4 | // 5 | // Created by 陈光远 on 16/1/26. 6 | // Copyright © 2016年 Facebook. All rights reserved. 7 | // 8 | 9 | #import "UMengManager.h" 10 | 11 | #import "RCTBridge.h" 12 | #import "RCTUtils.h" 13 | 14 | @implementation UMengManager 15 | 16 | @synthesize bridge = _bridge; 17 | 18 | -(void)shareToSns:(NSDictionary *)aData callback:(RCTResponseSenderBlock)callback{ 19 | self.callback = callback; 20 | 21 | dispatch_async(dispatch_get_main_queue(), ^{ 22 | //设置分享的点击链接 23 | [UMSocialData defaultData].extConfig.wechatSessionData.url = aData[@"url"]; 24 | [UMSocialData defaultData].extConfig.wechatTimelineData.url =aData[@"url"]; 25 | // [UMSocialData defaultData].extConfig.sinaData.url = aData[@"url"]; 26 | //设置分享图片 27 | [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeImage url:aData[@"image"]]; 28 | // 设置微信好友title 29 | [UMSocialData defaultData].extConfig.wechatSessionData.title = aData[@"title"]; 30 | // 设置微信朋友圈title 31 | [UMSocialData defaultData].extConfig.wechatTimelineData.title = aData[@"title"]; 32 | UIViewController *vc = RCTKeyWindow().rootViewController; 33 | [UMSocialSnsService presentSnsIconSheetView:vc 34 | appKey:UmengAppkey 35 | shareText:aData[@"text"] 36 | shareImage:nil 37 | shareToSnsNames:[NSArray arrayWithObjects:UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSms, 38 | UMShareToEmail,UMShareToSina,nil] 39 | delegate:self]; 40 | }); 41 | 42 | } 43 | 44 | //实现回调方法(可选): 45 | -(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response 46 | { 47 | //根据`responseCode`得到发送结果,如果分享成功 48 | if(response.responseCode == UMSResponseCodeSuccess) 49 | { 50 | //得到分享到的微博平台名 51 | self.callback(@[response.data]); 52 | // NSLog(@"-------share to sns name is %@",[[response.data allKeys] objectAtIndex:0]); 53 | } 54 | } 55 | 56 | 57 | -(void)postSNSWithTypes:(NSArray *)type params:(NSDictionary *)params callback:(RCTResponseSenderBlock)callback 58 | { 59 | UIViewController *vc = RCTKeyWindow().rootViewController; 60 | // 设置分享图片 61 | UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeImage url: 62 | params[@"image"]]; 63 | [[UMSocialDataService defaultDataService] postSNSWithTypes:type 64 | content:params[@"text"] 65 | image:nil 66 | location:nil 67 | urlResource:urlResource 68 | presentedController:vc 69 | completion:^(UMSocialResponseEntity *response){ 70 | if (response.responseCode == UMSResponseCodeSuccess) { 71 | NSLog(@"分享成功!"); 72 | callback(@[response.data]); 73 | } 74 | }]; 75 | } 76 | RCT_EXPORT_MODULE(); 77 | 78 | //调用umeng默认的分享 79 | RCT_EXPORT_METHOD(presentSnsIconSheetView:(NSDictionary *)data callback:(RCTResponseSenderBlock) callback) 80 | { 81 | 82 | [self shareToSns:data callback:callback]; 83 | 84 | } 85 | 86 | //直接调用微信好友分享 87 | RCT_EXPORT_METHOD(wechatSessionShare:(NSDictionary *)data callback:(RCTResponseSenderBlock) callback) 88 | { 89 | // data.type = UMShareToWechatSession; 90 | [self postSNSWithTypes:@[UMShareToWechatSession] params:data callback:callback]; 91 | } 92 | 93 | //记录页面加载 94 | RCT_EXPORT_METHOD(logPage:(NSString *) page) 95 | { 96 | [MobClick beginLogPageView:page];//("page"为页面名称) 97 | } 98 | 99 | //记录页面退出 100 | RCT_EXPORT_METHOD(endLogPageView:(NSString *) page) 101 | { 102 | [MobClick endLogPageView:page];//("page"为页面名称) 103 | } 104 | 105 | //记录事件 106 | RCT_EXPORT_METHOD(logEvent:(NSString *)eventId attributes:(NSDictionary *)attributes) 107 | { 108 | [MobClick event:(NSString *)eventId attributes:(NSDictionary *)attributes]; 109 | } 110 | @end --------------------------------------------------------------------------------