Skip to content

Commit

Permalink
feat: add PushUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
Damoness committed May 2, 2022
1 parent 814e3d5 commit bfb3729
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ReactNativeUmengExample",
"displayName": "ReactNativeUmeng Example",
"umeng": {
"appKey": "5c998a3561f564fc5e0011fe"
"appKey": "5c99854d0cafb25a2a0002f4"
},
"wechat-qichang": {
"appKey": "wx52dafcf5b9efb111",
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'
platform :ios, '12.0'

target 'ReactNativeUmengExample' do
config = use_native_modules!
Expand Down
12 changes: 9 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost-for-react-native (1.63.0)
- damoness-react-native-umeng (1.7.0):
- damoness-react-native-umeng (1.8.0):
- React-Core
- UMCommon
- UMDevice
Expand Down Expand Up @@ -194,6 +194,8 @@ PODS:
- React-cxxreact (= 0.63.4)
- React-jsi (= 0.63.4)
- React-jsinspector (0.63.4)
- react-native-notifications (4.3.1):
- React-Core
- React-RCTActionSheet (0.63.4):
- React-Core/RCTActionSheetHeaders (= 0.63.4)
- React-RCTAnimation (0.63.4):
Expand Down Expand Up @@ -302,6 +304,7 @@ DEPENDENCIES:
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- react-native-notifications (from `../node_modules/react-native-notifications`)
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
- React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`)
- React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`)
Expand Down Expand Up @@ -355,6 +358,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
React-jsinspector:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
react-native-notifications:
:path: "../node_modules/react-native-notifications"
React-RCTActionSheet:
:path: "../node_modules/react-native/Libraries/ActionSheetIOS"
React-RCTAnimation:
Expand All @@ -380,7 +385,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
damoness-react-native-umeng: 91fafb2c689ad8ccabeca4109366959503c4f77c
damoness-react-native-umeng: 67e217e4b9f8aa02d41c2a09ecd3fc43b682c285
DoubleConversion: cde416483dac037923206447da6e1454df403714
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
Expand All @@ -396,6 +401,7 @@ SPEC CHECKSUMS:
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
react-native-notifications: 33ec77006f7987bb22de8f1665889abc633b9196
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
Expand All @@ -412,6 +418,6 @@ SPEC CHECKSUMS:
UMShare: a3f9cb2d3ece67edd2c58331bd89bfffb289782b
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6

PODFILE CHECKSUM: ea3ebdaec3bf219bda106f7a8f3812d5818ce9b8
PODFILE CHECKSUM: 0dcdc94b5e0c3b80551eef467a737c9457823e5a

COCOAPODS: 1.11.2
15 changes: 10 additions & 5 deletions example/ios/ReactNativeUmengExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
47F7ED3B7971BE374F7B8635 /* Pods-ReactNativeUmengExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeUmengExample.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeUmengExample/Pods-ReactNativeUmengExample.debug.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = ReactNativeUmengExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
9C00D2EB27C9CB60001502EB /* ReactNativeUmengExampleDebug.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = ReactNativeUmengExampleDebug.entitlements; path = ReactNativeUmengExample/ReactNativeUmengExampleDebug.entitlements; sourceTree = "<group>"; };
9C60E206281F61320005BBF1 /* ReactNativeUmengExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = ReactNativeUmengExample.entitlements; path = ReactNativeUmengExample/ReactNativeUmengExample.entitlements; sourceTree = "<group>"; };
CA3E69C5B9553B26FBA2DF04 /* libPods-ReactNativeUmengExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeUmengExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
E00ACF0FDA8BF921659E2F9A /* Pods-ReactNativeUmengExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeUmengExample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeUmengExample/Pods-ReactNativeUmengExample.release.xcconfig"; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand All @@ -46,6 +47,7 @@
13B07FAE1A68108700A75B9A /* ReactNativeUmengExample */ = {
isa = PBXGroup;
children = (
9C60E206281F61320005BBF1 /* ReactNativeUmengExample.entitlements */,
9C00D2EB27C9CB60001502EB /* ReactNativeUmengExampleDebug.entitlements */,
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
Expand Down Expand Up @@ -139,7 +141,7 @@
LastUpgradeCheck = 1130;
TargetAttributes = {
13B07F861A680F5B00A75B9A = {
DevelopmentTeam = 8XXP5W7RV4;
DevelopmentTeam = X3384B9A6U;
LastSwiftMigration = 1120;
ProvisioningStyle = Manual;
};
Expand Down Expand Up @@ -277,19 +279,20 @@
CODE_SIGN_ENTITLEMENTS = ReactNativeUmengExample/ReactNativeUmengExampleDebug.entitlements;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8XXP5W7RV4;
DEVELOPMENT_TEAM = X3384B9A6U;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = ReactNativeUmengExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.8.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = com.zofund.crmmanage.test;
PRODUCT_BUNDLE_IDENTIFIER = com.inabr.qichang;
PRODUCT_NAME = ReactNativeUmengExample;
PROVISIONING_PROFILE_SPECIFIER = "Development _com.zofund.crmmanage.test";
PROVISIONING_PROFILE_SPECIFIER = "match Development com.inabr.qichang";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -302,18 +305,20 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = ReactNativeUmengExample/ReactNativeUmengExample.entitlements;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8XXP5W7RV4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = ReactNativeUmengExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 3.8.4;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = com.zofund.crmmanage.test;
PRODUCT_BUNDLE_IDENTIFIER = com.inabr.qichang;
PRODUCT_NAME = ReactNativeUmengExample;
PROVISIONING_PROFILE_SPECIFIER = "Development _com.zofund.crmmanage.test";
SWIFT_VERSION = 5.0;
Expand Down
31 changes: 26 additions & 5 deletions example/ios/ReactNativeUmengExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// ------
//友盟
#import <UMCommon/UMCommon.h>

//友盟统计
#import <UMCommon/MobClick.h>

Expand All @@ -30,6 +31,8 @@
// ------


#import <UMPush/UMessage.h>

#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
Expand All @@ -48,6 +51,8 @@ static void InitializeFlipper(UIApplication *application) {
}
#endif

#import "RNNotifications.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand All @@ -56,8 +61,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
InitializeFlipper(application);
#endif

//[self initUMeng];

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"ReactNativeUmengExample"
Expand All @@ -70,6 +73,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];


[RNNotifications startMonitorNotifications];

return YES;
}

Expand Down Expand Up @@ -100,13 +107,12 @@ - (void)initUMeng{
/* 设置微信的appKey和appSecret */
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:WXAppKey appSecret:WXAppSecret redirectURL:nil];


/* 设置企业微信 */
// [UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatWork appKey:<#(NSString *)#> appSecret:<#(NSString *)#> redirectURL:<#(NSString *)#>

}




//URI Scheme
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options{

Expand All @@ -127,4 +133,19 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct
return YES;
}

#pragma mark - 推送

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[UMessage registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
[RNNotifications didReceiveBackgroundNotification:userInfo withCompletionHandler:completionHandler];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:testzowxzb.newtamp.cn</string>
Expand Down
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"dependencies": {
"react": "16.13.1",
"react-native": "0.63.4"
"react-native": "0.63.4",
"react-native-notifications": "^4.3.1"
},
"devDependencies": {
"@babel/core": "^7.12.10",
Expand Down
93 changes: 93 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import {
Text,
View,
TouchableOpacity,
Alert,
} from 'react-native';
import {
ShareUtil,
Configure,
SharePlatform,
PushUtil,
} from '@damoness/react-native-umeng';

import { Notifications } from 'react-native-notifications';

import appJSON from '../app.json';

let { umeng, wechatWork, wechat } = appJSON;
Expand Down Expand Up @@ -88,6 +92,13 @@ export default function App() {
);
}
init();

Notifications.getInitialNotification().then((x) => {
if (x) {
console.log('x', JSON.stringify(x));
Alert.alert(x.payload.aps.alert.title);
}
});
}, []);

return (
Expand Down Expand Up @@ -141,6 +152,88 @@ export default function App() {
...getCommonFunctionData(SharePlatform.Wechat_TimeLine).slice(1),
],
},

{
title: '推送',
data: [
{
title: '请求推送',
onPress: () => {
Notifications.registerRemoteNotifications();

Notifications.events().registerRemoteNotificationsRegistered(
(event) => {
// TODO: Send the token to my server so it could send back push notifications...
console.log('Device Token Received', event.deviceToken);
}
);

Notifications.events().registerNotificationReceivedForeground(
(notification, completion) => {
console.log(
`Notification received in foreground: ${notification.title} : ${notification.body}`
);
completion({ alert: true, sound: true, badge: true });
}
);

Notifications.events().registerNotificationOpened(
(notification, completion) => {
console.log(
`Notification opened: ${JSON.stringify(
notification.payload
)}`
);

Alert.alert(notification.payload.aps.alert.title);
completion();
}
);
},
},
{
title: '增加标签',
onPress: async () => {
let remain = await PushUtil.addTag(
'a' + Math.floor(Math.random() * 100)
);
console.log('remain', remain);
},
},
{
title: '删除标签',
onPress: async () => {},
},
{
title: '获取标签列表',
onPress: async () => {
let list = await PushUtil.getTagList();
console.log('data', list);
},
},
{
title: '增加别名',
onPress: async () => {
let r = await PushUtil.addAlias('test1', 'a2');
console.log('r', r);
},
},
{
title: '增加排他别名',
onPress: async () => {
let r = await PushUtil.addExclusiveAlias('test2', 'aaaa');
console.log('r', r);
},
},
{
title: '删除别名',
onPress: async () => {
let r = await PushUtil.deleteAlias('test1', 'aaaa');
console.log('r', r);
},
},
],
},
]}
keyExtractor={(item, index) => item.title + index}
renderSectionHeader={({ section: { title } }) => (
Expand Down
5 changes: 5 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3464,6 +3464,11 @@ react-is@^16.12.0, react-is@^16.8.1, react-is@^16.8.4:
resolved "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-native-notifications@^4.3.1:
version "4.3.1"
resolved "https://registry.npmjs.org/react-native-notifications/-/react-native-notifications-4.3.1.tgz#ad9a8e6881bc17cf03ef16d4dfdaee9ec8bb721d"
integrity sha512-A668d+Q0/VQRjmrh+LvDpc/REA8GXgwCijXDCIlDHGMK8enmrtdxY5OANQf1VM3hecf+fD0wYFw2uqL/ZR8jgg==

react-native@0.63.4:
version "0.63.4"
resolved "https://registry.npmjs.org/react-native/-/react-native-0.63.4.tgz#2210fdd404c94a5fa6b423c6de86f8e48810ec36"
Expand Down
Loading

0 comments on commit bfb3729

Please sign in to comment.