countly-sdk-react-native-bridge
Advanced tools
Comparing version 19.8.1 to 19.8.2
@@ -352,3 +352,3 @@ /** | ||
} | ||
CountlyReactNative.giveConsent(features); | ||
CountlyReactNative.removeConsent(features); | ||
} | ||
@@ -440,10 +440,2 @@ | ||
Countly.setupPush = function(messagingMode, options) { | ||
if (Platform.OS.match("android")) { | ||
CountlyReactNative.setupPush(messagingMode, options); | ||
} | ||
else { | ||
console.log("Not implemented for IOS yet.") | ||
} | ||
} | ||
@@ -450,0 +442,0 @@ if (ErrorUtils) { |
@@ -9,110 +9,75 @@ import React, { Component } from 'react'; | ||
import { DeviceEventEmitter } from 'react-native'; | ||
import {NativeModules} from 'react-native'; | ||
const CountlyPush = NativeModules.CountlyReactNativePush; | ||
class AwesomeProject extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.config = {}; | ||
}; | ||
onInit(){ | ||
Countly.init("https://izzet.count.ly","6559f034a0a76bc7190d10a217a4052b9f8a2a59","","5", "Rate us.", "How would you rate the app?", "Dismiss",false); | ||
Countly.enableLogging(); } | ||
onStart(){ | ||
Countly.start(); | ||
}; | ||
onStop(){ | ||
Countly.stop(); | ||
}; | ||
onSendUserData(){ | ||
// example for setUserData | ||
var options = {}; | ||
options.name = "Trinisoft Technologies"; | ||
options.username = "trinisofttechnologies"; | ||
options.email = "trinisofttechnologies@gmail.com"; | ||
options.org = "Trinisoft Technologies Pvt. Ltd."; | ||
options.phone = "+91 812 840 2946"; | ||
options.picture = "http://www.trinisofttechnologies.com/images/logo.png"; | ||
options.picturePath = ""; | ||
options.gender = "M"; | ||
options.byear = 1989; | ||
Countly.setUserData(options); | ||
}; | ||
basicEvent(){ | ||
// example for basic event | ||
var event = {"eventName":"Basic Event","eventCount":1}; | ||
Countly.sendEvent(event); | ||
}; | ||
constructor(props) { | ||
super(props); | ||
this.config = {}; | ||
}; | ||
onInit(){ | ||
Countly.init("https://XXXX.count.ly","12345XYZ"); | ||
Countly.enableLogging(); | ||
} | ||
onStart(){ | ||
Countly.start(); | ||
}; | ||
onStop(){ | ||
Countly.stop(); | ||
}; | ||
basicEvent(){ | ||
// example for basic event | ||
var event = {"eventName":"Basic Event","eventCount":1}; | ||
Countly.sendEvent(event); | ||
}; | ||
setupPush(){ | ||
setupPush(){ | ||
console.log('setupPush'); | ||
if (Platform.OS.match("android")) { | ||
var options = { channelName: "Demo App Notifications", channelDescription: "<![CDATA[Messages from Demo App]]>"} | ||
Countly.setupPush(Countly.messagingMode.DEVELOPMENT, options); | ||
DeviceEventEmitter.addListener('push_notification', payload => { | ||
console.log("Notification received", payload); | ||
}); | ||
var options = { channelName: "Demo App Notifications", channelDescription: "<![CDATA[Messages from Demo App]]>"} | ||
CountlyPush.setupPush(Countly.messagingMode.DEVELOPMENT, options); | ||
DeviceEventEmitter.addListener('push_notification', payload => { | ||
console.log("Notification received", payload); | ||
}); | ||
} | ||
else { | ||
PushNotificationIOS.addEventListener('registrationError', function(error){ | ||
console.log('error:', error); | ||
}); | ||
PushNotification.configure({ | ||
onRegister: function(token) { | ||
console.log( 'TOKEN:', token ); | ||
var options = { | ||
token: token.token, | ||
messagingMode: Countly.messagingMode.DEVELOPMENT | ||
} | ||
Countly.sendPushToken(options) | ||
}, | ||
onNotification: function(notification) { | ||
console.log( 'NOTIFICATION:', notification ); | ||
// process the notification | ||
// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html) | ||
notification.finish(PushNotificationIOS.FetchResult.NoData); | ||
}, | ||
// ANDROID ONLY: GCM or FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications) | ||
senderID: "881000050249", | ||
// IOS ONLY (optional): default: all - Permissions to register. | ||
permissions: { | ||
alert: true, | ||
badge: true, | ||
sound: true | ||
}, | ||
} | ||
// Should the initial notification be popped automatically | ||
// default: true | ||
popInitialNotification: true, | ||
/** | ||
* (optional) default: true | ||
* - Specified if permissions (ios) and token (android and ios) will requested or not, | ||
* - if not, you must call PushNotificationsHandler.requestPermissions() later | ||
*/ | ||
requestPermissions: true, | ||
}); | ||
} | ||
requireConsent(){ | ||
Countly.setRequiresConsent(true); | ||
} | ||
} | ||
giveConsent(){ | ||
Countly.giveConsent("push"); | ||
} | ||
removeConsent(){ | ||
Countly.removeConsent("push"); | ||
} | ||
render() { | ||
return ( | ||
<ScrollView > | ||
<View style={{ justifyContent: 'center', alignItems: 'center', margin: 20 }}> | ||
<Image source={{uri: 'https://community.count.ly/uploads/default/original/1X/ed53a7c24391bfde820b44b1de9a044352f718b0.png'}} style={{width: 150, height: 45}} onError={(e) => console.log(e.nativeEvent.error) }/> | ||
<Text style={[{fontSize:24, textAlign: 'center'}]}>React Native Demo App</Text> | ||
</View> | ||
< Button onPress = { this.onInit } title = "Init"> </Button> | ||
< Button onPress = { this.onStart } title = "Start" color = "#5bbd72"> </Button> | ||
< Button onPress = { this.onStop } title = "Stop" color = "#d95c5c"> </Button> | ||
< Button onPress = { this.basicEvent } title = "Basic Events" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.setupPush } title='Setup Push' color='#00b5ad' /> | ||
render() { | ||
</ScrollView> | ||
); | ||
} | ||
return ( | ||
<ScrollView > | ||
<View style={{ justifyContent: 'center', alignItems: 'center', margin: 20 }}> | ||
<Image source={{uri: 'https://community.count.ly/uploads/default/original/1X/ed53a7c24391bfde820b44b1de9a044352f718b0.png'}} style={{width: 150, height: 45}} onError={(e) => console.log(e.nativeEvent.error) }/> | ||
<Text style={[{fontSize:24, textAlign: 'center'}]}>React Native Demo App</Text> | ||
</View> | ||
< Button onPress = { this.onInit } title = "Init"> </Button> | ||
< Button onPress = { this.onStart } title = "Start" color = "#5bbd72"> </Button> | ||
< Button onPress = { this.onStop } title = "Stop" color = "#d95c5c"> </Button> | ||
< Button onPress = { this.basicEvent } title = "Basic Events" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.setupPush } title='Setup Push' color='#00b5ad' /> | ||
< Button onPress = { this.requireConsent } title='Require Consent' color='#00b5ad' /> | ||
< Button onPress = { this.giveConsent } title='Give consent for push' color='#00b5ad' /> | ||
< Button onPress = { this.removeConsent } title='Remove consent for push' color='#00b5ad' /> | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
@@ -119,0 +84,0 @@ |
@@ -5,3 +5,3 @@ | ||
*Usual Instructions for setting up App but npm install from this branch* | ||
*Usual Instructions for setting up App* | ||
``` | ||
@@ -14,3 +14,4 @@ react-native init DemoProject # Create a new project | ||
# Include SDK | ||
npm install --save https://github.com/Countly/countly-sdk-react-native-bridge.git#android-push | ||
npm install --save https://github.com/Countly/countly-sdk-react-native-bridge.git | ||
# this may not be necessary if you are using React Native >= 0.6 | ||
react-native link countly-sdk-react-native-bridge | ||
@@ -23,6 +24,8 @@ | ||
# In root of DemoProject | ||
react-native run-android # OR # Run the android project | ||
react-native run-ios # Run the iOS project | ||
react-native run-android # Run the android project | ||
# use following if you don't want androidx with React Native >= 0.6 | ||
react-native run-android --no-jetifier | ||
``` | ||
@@ -64,8 +67,19 @@ *Now comes the steps for FCM integration* | ||
* Copy `DemoFirebaseMessagingService.java` found here under `android/app/src/main/java/<YOUR_PACKAGE_PATH>`. It should reside near `MainActivity.java`. Change the package name at the top of this file to match your package name. | ||
* Copy `DemoFirebaseMessagingService.java`, `CountlyReactNativePushPackage.java`, `CountlyReactNativePush.java`, `MainApplication.java`, `MainActivity.java` found here under `android/app/src/main/java/<YOUR_PACKAGE_PATH>`. This is the folder where `react-native init` created `MainActivity.java` automatically. Change the package name at the top of these files to match your package name. Critical change in `MainApplication.java` to use new native module `CountlyReactNativePush` is this part: | ||
* Copy `ic_message.png` found here into `android/app/src/main/res/drawable`. Create `drawable` folder if necessary. | ||
```java | ||
@Override | ||
protected List<ReactPackage> getPackages() { | ||
@SuppressWarnings("UnnecessaryLocalVariable") | ||
List<ReactPackage> packages = new PackageList(this).getPackages(); | ||
// Packages that cannot be autolinked yet can be added manually here, for example: | ||
packages.add(new CountlyReactNativePushPackage()); | ||
return packages; | ||
} | ||
``` | ||
*I think that's it. After setting your countly server and app key, you can launch the app. First call/press init, start (may be send a basic event just to make sure) then hit "Setup Push" button. This will get the token from FCM service and send it to Countly (logs should look like below). Then you can test sending message from Countly server.* | ||
* Copy `ic_message.png` found here into `android/app/src/main/res/drawable`. Create `drawable` folder if necessary. This is the icon used in notifications. | ||
* After setting your countly server and app key in `App.js`, you can launch the app. First call/press init, start (may be send a basic event just to make sure) then hit "Setup Push" button. This will get the token from FCM service and send it to Countly (logs should look like below). Then you can test sending message from Countly server. If you want, you can test consent by requiring consent first and then removing consent for push. | ||
``` | ||
@@ -72,0 +86,0 @@ # Logs after Setup Push |
{ | ||
"name": "countly-sdk-react-native-bridge", | ||
"version": "19.8.1", | ||
"version": "19.8.2", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Trinisoft Technologies", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
489041
74
1735