countly-sdk-react-native-bridge
Advanced tools
Comparing version 19.8.6 to 20.4.0
@@ -299,2 +299,5 @@ /** | ||
} | ||
Countly.cancelEvent = function(eventName){ | ||
CountlyReactNative.cancelEvent([eventName.toString() || ""]); | ||
} | ||
Countly.endEvent = function(options){ | ||
@@ -301,0 +304,0 @@ if(typeof options === "string") { |
import React, { Component } from 'react'; | ||
import { AppRegistry, Text, Button, ScrollView, Image, View, Alert } from 'react-native'; | ||
import Countly from 'countly-sdk-react-native-bridge'; | ||
// import { PushNotificationIOS } from 'react-native'; | ||
// import StackTrace from '/Countly.StackTrace.js'; | ||
// import stacktrace from 'react-native-stacktrace'; | ||
// var PushNotification = require('react-native-push-notification'); | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { createStackNavigator } from '@react-navigation/stack'; | ||
import { AppRegistry } from 'react-native'; | ||
import Example from "./Example.js"; | ||
// import AutoTracking from "./AutoTracking.js"; | ||
function autoTrackingView(state){ | ||
var viewName = state.routes[state.routes.length -1].name; | ||
console.log("autoTrackingView"); | ||
console.log(viewName); | ||
Countly.recordView(viewName); | ||
} | ||
// Auto Navigation Example. | ||
const Stack = createStackNavigator(); | ||
export const navigationRef = React.createRef(); | ||
export function navigate(name){ | ||
navigationRef.current?.navigate(name); | ||
} | ||
class PageOne extends Component { | ||
render(){ | ||
return( | ||
<ScrollView> | ||
<Text>Page One</Text> | ||
<Button onPress={() => navigate('PageOne')} title="Go to Page One"></Button> | ||
<Button onPress={() => navigate('PageTwo')} title="Go to Page Two"></Button> | ||
<Button onPress={() => navigate('PageThree')} title="Go to Page Three"></Button> | ||
<Button onPress={() => navigate('Example')} title="Go to Page Example"></Button> | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
class PageTwo extends Component { | ||
render(){ | ||
return( | ||
<View> | ||
<Text>Page Two</Text> | ||
<Button onPress={() => navigate('PageOne')} title="Go to Page One"></Button> | ||
<Button onPress={() => navigate('PageTwo')} title="Go to Page Two"></Button> | ||
<Button onPress={() => navigate('PageThree')} title="Go to Page Three"></Button> | ||
<Button onPress={() => navigate('Example')} title="Go to Page Example"></Button> | ||
</View> | ||
); | ||
} | ||
} | ||
class PageThree extends Component { | ||
render(){ | ||
return( | ||
<View> | ||
<Text>Page Three</Text> | ||
<Button onPress={() => navigate('PageOne')} title="Go to Page One"></Button> | ||
<Button onPress={() => navigate('PageTwo')} title="Go to Page Two"></Button> | ||
<Button onPress={() => navigate('PageThree')} title="Go to Page Three"></Button> | ||
<Button onPress={() => navigate('Example')} title="Go to Page Example"></Button> | ||
</View> | ||
); | ||
} | ||
} | ||
// Auto Navigation Example. | ||
class AwesomeProject extends Component { | ||
render() { | ||
return ( | ||
<NavigationContainer ref={navigationRef} onStateChange={autoTrackingView}> | ||
<Stack.Navigator initialRouteName="Example"> | ||
<Stack.Screen name="Example" component = {Example} /> | ||
<Stack.Screen name="PageOne" component={PageOne} /> | ||
<Stack.Screen name="PageTwo" component={PageTwo} /> | ||
<Stack.Screen name="PageThree" component={PageThree} /> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
<Example/> | ||
// <AutoTracking/> | ||
) | ||
} | ||
} | ||
class Example extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.config = {}; | ||
this.onInit = this.onInit.bind(this); | ||
this.onStart = this.onStart.bind(this); | ||
this.basicEvent = this.basicEvent.bind(this); | ||
this.eventWithSum = this.eventWithSum.bind(this); | ||
this.eventWithSegment = this.eventWithSegment.bind(this); | ||
this.eventWithSumAndSegment = this.eventWithSumAndSegment.bind(this); | ||
this.startEvent = this.startEvent.bind(this); | ||
this.test = this.test.bind(this); | ||
this.onSendUserData = this.onSendUserData.bind(this); | ||
this.userData_setProperty = this.userData_setProperty.bind(this); | ||
this.userData_increment = this.userData_increment.bind(this); | ||
this.userData_multiply = this.userData_multiply.bind(this); | ||
this.userData_saveMax = this.userData_saveMax.bind(this); | ||
this.userData_saveMin = this.userData_saveMin.bind(this); | ||
this.userData_setOnce = this.userData_setOnce.bind(this); | ||
this.changeDeviceId = this.changeDeviceId.bind(this); | ||
this.enableParameterTamperingProtection = this.enableParameterTamperingProtection.bind(this); | ||
}; | ||
componentDidMount(){ | ||
console.log("registerForNotification"); | ||
Countly.registerForNotification(function(theNotification){ | ||
console.log(JSON.stringify(theNotification)); | ||
console.log('theNotification'); | ||
}); | ||
} | ||
onInit(){ | ||
Countly.pushTokenType(Countly.messagingMode.DEVELOPMENT); | ||
Countly.init("https://trinisoft.count.ly", "f0b2ac6919f718a13821575db28c0e2971e05ec5"); | ||
// Countly.init("https://try.count.ly","0e8a00e8c01395a0af8be0e55da05a404bb23c3e"); | ||
// ,"","5", "Rate us.", "How would you rate the app?", "Dismiss",false | ||
} | ||
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); | ||
}; | ||
eventWithSum(){ | ||
// example for event with sum | ||
var event = {"eventName":"Event With Sum","eventCount":1,"eventSum":"0.99"}; | ||
Countly.sendEvent(event); | ||
}; | ||
eventWithSegment(){ | ||
// example for event with segment | ||
var event = {"eventName":"Event With Segment","eventCount":1}; | ||
event.segments = {"Country" : "Turkey", "Age" : "28"}; | ||
Countly.sendEvent(event); | ||
event = {"eventName":"Event With Segment","eventCount":1}; | ||
event.segments = {"Country" : "France", "Age" : "38"}; | ||
Countly.sendEvent(event); | ||
}; | ||
eventWithSumAndSegment(){ | ||
// example for event with segment and sum | ||
var event = {"eventName":"Event With Sum And Segment","eventCount":1,"eventSum":"0.99"}; | ||
event.segments = {"Country" : "Turkey", "Age" : "28"}; | ||
Countly.sendEvent(event); | ||
event = {"eventName":"Event With Sum And Segment","eventCount":3,"eventSum":"1.99"}; | ||
event.segments = {"Country" : "France", "Age" : "38"}; | ||
Countly.sendEvent(event); | ||
}; | ||
// TIMED EVENTS | ||
startEvent(){ | ||
Countly.startEvent("timedEvent"); | ||
setTimeout(function(){ | ||
Countly.endEvent("timedEvent"); | ||
},1000); | ||
}; | ||
/* | ||
setTimeout may not work correctly if you are attached to Chrome Debugger. | ||
for workaround see: https://github.com/facebook/react-native/issues/9436 | ||
*/ | ||
timedEventWithSum(){ | ||
// Event with sum | ||
Countly.startEvent("timedEventWithSum"); | ||
var event = { | ||
"eventName": "timedEventWithSum", | ||
"eventSum": "0.99" | ||
}; | ||
setTimeout(function(){ | ||
Countly.endEvent(event); | ||
},1000); | ||
}; | ||
timedEventWithSegment(){ | ||
// Event with segment | ||
Countly.startEvent("timedEventWithSegment"); | ||
var event = { | ||
"eventName": "timedEventWithSegment" | ||
}; | ||
event.segments = { | ||
"Country": "Germany", | ||
"Age": "32" | ||
}; | ||
setTimeout(function(){ | ||
Countly.endEvent(event); | ||
},1000); | ||
}; | ||
timedEventWithSumAndSegment(){ | ||
// Event with Segment, sum and count | ||
Countly.startEvent("timedEventWithSumAndSegment"); | ||
var event = { | ||
"eventName": "timedEventWithSumAndSegment", | ||
"eventCount": 1, | ||
"eventSum": "0.99" | ||
}; | ||
event.segments = { | ||
"Country": "India", | ||
"Age": "21" | ||
}; | ||
setTimeout(function(){ | ||
Countly.endEvent(event); | ||
},1000); | ||
}; | ||
// TIMED EVENTS | ||
userData_setProperty(){ | ||
Countly.userData.setProperty("setProperty", "keyValue"); | ||
}; | ||
userData_increment(){ | ||
Countly.userData.setProperty("increment", 5); | ||
Countly.userData.increment("increment"); | ||
}; | ||
userData_incrementBy(){ | ||
Countly.userData.setProperty("incrementBy", 5); | ||
Countly.userData.incrementBy("incrementBy", 10); | ||
}; | ||
userData_multiply(){ | ||
Countly.userData.setProperty("multiply", 5); | ||
Countly.userData.multiply("multiply", 20); | ||
}; | ||
userData_saveMax(){ | ||
Countly.userData.setProperty("saveMax", 5); | ||
Countly.userData.saveMax("saveMax", 100); | ||
}; | ||
userData_saveMin(){ | ||
Countly.userData.setProperty("saveMin", 5); | ||
Countly.userData.saveMin("saveMin", 50); | ||
}; | ||
userData_setOnce(){ | ||
Countly.userData.setOnce("setOnce", 200); | ||
}; | ||
userData_pushUniqueValue(){ | ||
Countly.userData.pushUniqueValue("type", "morning"); | ||
}; | ||
userData_pushValue(){ | ||
Countly.userData.pushValue("type", "morning"); | ||
}; | ||
userData_pullValue(){ | ||
Countly.userData.pullValue("type", "morning"); | ||
}; | ||
onRegisterDevice(){ | ||
// Countly.initMessaging('403185924621', Countly.TEST); | ||
} | ||
changeDeviceId(){ | ||
Countly.changeDeviceId('02d56d66-6a39-482d-aff0-d14e4d5e5fda'); | ||
}; | ||
enableParameterTamperingProtection(){ | ||
Countly.enableParameterTamperingProtection("salt"); | ||
}; | ||
setRequiresConsent(){ | ||
Countly.setRequiresConsent(true); | ||
} | ||
giveEventsConsent(){ | ||
Countly.giveConsent("events"); | ||
}; | ||
removeEventsConsent(){ | ||
Countly.removeConsent("events"); | ||
}; | ||
giveMultipleConsent(){ | ||
Countly.giveConsent(["events", "views", "star-rating", "crashes", "invalidFeatureName"]); | ||
}; | ||
removeMultipleConsent(){ | ||
Countly.removeConsent(["events", "views"]); | ||
}; | ||
giveAllConsent(){ | ||
Countly.giveAllConsent(); | ||
}; | ||
removeAllConsent(){ | ||
Countly.removeAllConsent(); | ||
}; | ||
remoteConfigUpdate(){ | ||
Countly.remoteConfigUpdate(function(data){ | ||
console.log(data); | ||
}); | ||
}; | ||
updateRemoteConfigForKeysOnly(){ | ||
Countly.updateRemoteConfigForKeysOnly(["test1"],function(data){ | ||
console.log(data); | ||
}); | ||
}; | ||
updateRemoteConfigExceptKeys(){ | ||
Countly.updateRemoteConfigExceptKeys(["test1"],function(data){ | ||
console.log(data); | ||
}); | ||
}; | ||
getRemoteConfigValueForKeyBoolean(){ | ||
Countly.getRemoteConfigValueForKey("booleanValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyFloat(){ | ||
Countly.getRemoteConfigValueForKey("floatValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyInteger(){ | ||
Countly.getRemoteConfigValueForKey("integerValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyString(){ | ||
Countly.getRemoteConfigValueForKey("stringValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyJSON(){ | ||
Countly.getRemoteConfigValueForKey("jsonValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
remoteConfigClearValues(){ | ||
Countly.remoteConfigClearValues(); | ||
}; | ||
setLocation(){ | ||
var countryCode = "us"; | ||
var city = "Houston"; | ||
var latitude = "29.634933"; | ||
var longitude = "-95.220255"; | ||
var ipAddress = "103.238.105.167"; | ||
Countly.setLocation(countryCode, city, latitude + "," + longitude, ipAddress); | ||
}; | ||
disableLocation(){ | ||
Countly.disableLocation(); | ||
}; | ||
setupPush(){ | ||
Countly.askForNotificationPermission(); | ||
// console.log('setupPush'); | ||
// 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, | ||
// }); | ||
} | ||
enableLogging(){ | ||
Countly.enableLogging(); | ||
}; | ||
disableLogging(){ | ||
Countly.disableLogging(); | ||
}; | ||
setStarRatingDialogTexts(){ | ||
Countly.setStarRatingDialogTexts(); | ||
}; | ||
showStarRating(){ | ||
Countly.showStarRating(); | ||
}; | ||
showFeedbackPopup(){ | ||
Countly.showFeedbackPopup("5e4254507975d006a22535fc", "Submit"); | ||
} | ||
enableCrashReporting(){ | ||
Countly.enableCrashReporting(); | ||
}; | ||
addCrashLog(){ | ||
Countly.addCrashLog("My crash log in string."); | ||
}; | ||
addLogException(){ | ||
Countly.addCrashLog("User Performed Step A"); | ||
setTimeout(function(){ | ||
Countly.addCrashLog("User Performed Step B"); | ||
},1000); | ||
setTimeout(function(){ | ||
Countly.addCrashLog("User Performed Step C"); | ||
try { | ||
var a = {}; | ||
var x = a.b.c; // this will create error. | ||
} catch (error) { | ||
setTimeout(function(){ | ||
var stack = error.stack.toString(); | ||
Countly.logException(stack, true, {"_facebook_version": "0.0.1"}); | ||
},1000); | ||
} | ||
},1000); | ||
}; | ||
logException(){ | ||
Countly.logException(); | ||
} | ||
setEventSendThreshold(){ | ||
Countly.setEventSendThreshold("3"); | ||
} | ||
/* | ||
initNative(){ | ||
Countly.initNative(); | ||
}; | ||
testCrash(){ | ||
Countly.testCrash(); | ||
} | ||
*/ | ||
test(){ | ||
this.onInit(); | ||
this.onStart(); | ||
this.basicEvent(); | ||
this.eventWithSum(); | ||
this.eventWithSegment(); | ||
this.eventWithSumAndSegment(); | ||
this.startEvent(); | ||
this.onSendUserData(); | ||
this.userData_setProperty(); | ||
this.userData_increment(); | ||
this.userData_incrementBy(); | ||
this.userData_multiply(); | ||
this.userData_saveMax(); | ||
this.userData_saveMin(); | ||
this.userData_setOnce(); | ||
// this.changeDeviceId(); | ||
this.enableParameterTamperingProtection(); | ||
} | ||
render() { | ||
return ( | ||
<ScrollView > | ||
<View style={{ justifyContent: 'center', alignItems: 'center', margin: 20 }}> | ||
<Image source={{uri: 'https://count.ly/images/logos/countly-logo.png'}} style={ {width: 144, height: 42} } onError={(e) => console.log(e.nativeEvent.error) }/> | ||
<Text style={[{fontSize:24, textAlign: 'center'}]}>React Native Demo App</Text> | ||
</View> | ||
<Button onPress={() => navigate('PageOne')} title="Go to Page One"></Button> | ||
< Button onPress = { this.test } title = "Test" color = "#1b1c1d"> </Button> | ||
< 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> | ||
<Text style={[{textAlign: 'center'}]}>Events Start</Text> | ||
< Button onPress = { this.basicEvent } title = "Basic Events" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.eventWithSum } title = "Event with Sum" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.eventWithSegment } title = "Event with Segment" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.eventWithSumAndSegment } title = "Even with Sum and Segment" color = "#841584"> </Button> | ||
< Button onPress = { this.startEvent } title = "Timed event" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.timedEventWithSum } title = "Timed events with Sum" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.timedEventWithSegment } title = "Timed events with Segment" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.timedEventWithSumAndSegment } title = "Timed events with Sum and Segment" color = "#e0e0e0"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>Events End</Text> | ||
<Text style={[{textAlign: 'center'}]}>2017</Text> | ||
<Text style={[{textAlign: 'center'}]}>User Methods Start</Text> | ||
< Button onPress = { this.onSendUserData } title = "Send Users Data" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_setProperty } title = "UserData.setProperty" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_increment } title = "UserData.increment" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_incrementBy } title = "UserData.incrementBy" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_multiply } title = "UserData.multiply" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_saveMax } title = "UserData.saveMax" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_saveMin } title = "UserData.saveMin" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_setOnce } title = "UserData.setOnce" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_pushUniqueValue } title = "UserData.pushUniqueValue" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_pushValue } title = "UserData.pushValue" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_pullValue } title = "UserData.pullValue" color = "#00b5ad"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>User Methods End</Text> | ||
<Text style={[{textAlign: 'center'}]}>Other Methods Start</Text> | ||
< Button onPress = { function(){Countly.recordView("HomePage")} } title = "Record View: 'HomePage'" color = "#e0e0e0"> </Button> | ||
< Button onPress = { function(){Countly.recordView("Dashboard")} } title = "Record View: 'Dashboard'" color = "#e0e0e0"> </Button> | ||
< Button onPress={this.enableLogging} title='Enable Logging' color='#00b5ad' /> | ||
< Button onPress={this.disableLogging} title='Disable Logging' color='#00b5ad' /> | ||
< Text style={[{ textAlign: 'center' }]}>Push Notification Start</Text> | ||
< Button onPress={this.setupPush} title='Register Device' color='#00b5ad' /> | ||
< Button onPress={this.changeDeviceId} title='Change Device ID' color='#00b5ad' /> | ||
< Text style={[{ textAlign: 'center' }]}>Push Notification End</Text> | ||
< Button onPress = { this.enableParameterTamperingProtection } title = "Enable Parameter Tapmering Protection" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.setRequiresConsent } title = "Init Consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.giveEventsConsent } title = "Give events consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.removeEventsConsent } title = "Remove events consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.giveMultipleConsent } title = "Give multiple consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.removeMultipleConsent } title = "Remove multiple consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.giveAllConsent } title = "Give all Consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.removeAllConsent } title = "Remove all Consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.setLocation } title = "Set Location" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.disableLocation } title = "Disable Location" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.remoteConfigUpdate } title = "Update Remote Config" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.updateRemoteConfigForKeysOnly } title = "Update Remote Config with Keys Only" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.updateRemoteConfigExceptKeys } title = "Update Remote Config Except Keys" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyBoolean } title = "Boolean Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyFloat } title = "Float Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyInteger } title = "Integer Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyString } title = "String Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyJSON } title = "JSON Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.remoteConfigClearValues } title = "Clear remote config cache" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.showStarRating } title = "Show Star Rating Model" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.showFeedbackPopup } title = "Show FeedBack Model" color = "#00b5ad"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>Other Methods End</Text> | ||
<Text style={[{textAlign: 'center'}]}>Crash Event start</Text> | ||
< Button onPress = { this.enableCrashReporting } title = "Enable Crash Reporting" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.addCrashLog } title = "Add Crash Log" color = "#00b5ad"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>Crash Event End</Text> | ||
< Button onPress = { this.eventSendThreshold } title = "Set Event Threshold" color = "#00b5ad"> </Button> | ||
{/* | ||
< Button onPress = { this.initNative } title = "Init Native" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.testCrash } title = "Test Native Crash" color = "crimson"> </Button> | ||
*/} | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
module.exports = AwesomeProject; | ||
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); |
@@ -12,562 +12,14 @@ /** | ||
import { AppRegistry, Button, ScrollView, Image, Alert } from 'react-native'; | ||
import Countly from 'countly-sdk-react-native-bridge'; | ||
// var PushNotification = require('react-native-push-notification'); | ||
const instructions = Platform.select({ | ||
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', | ||
android: | ||
'Double tap R on your keyboard to reload,\n' + | ||
'Shake or press menu button for dev menu', | ||
}); | ||
import Example from './Example.js'; | ||
type Props = {}; | ||
export default class App extends Component<Props> { | ||
constructor(props) { | ||
super(props); | ||
this.config = {}; | ||
constructor(props) { super(props); }; | ||
render() { | ||
return ( | ||
<Example /> | ||
); | ||
} | ||
} | ||
this.onInit = this.onInit.bind(this); | ||
this.onStart = this.onStart.bind(this); | ||
this.basicEvent = this.basicEvent.bind(this); | ||
this.eventWithSum = this.eventWithSum.bind(this); | ||
this.eventWithSegment = this.eventWithSegment.bind(this); | ||
this.eventWithSumAndSegment = this.eventWithSumAndSegment.bind(this); | ||
this.startEvent = this.startEvent.bind(this); | ||
this.test = this.test.bind(this); | ||
this.onSendUserData = this.onSendUserData.bind(this); | ||
this.userData_setProperty = this.userData_setProperty.bind(this); | ||
this.userData_increment = this.userData_increment.bind(this); | ||
this.userData_multiply = this.userData_multiply.bind(this); | ||
this.userData_saveMax = this.userData_saveMax.bind(this); | ||
this.userData_saveMin = this.userData_saveMin.bind(this); | ||
this.userData_setOnce = this.userData_setOnce.bind(this); | ||
this.changeDeviceId = this.changeDeviceId.bind(this); | ||
this.enableParameterTamperingProtection = this.enableParameterTamperingProtection.bind(this); | ||
}; | ||
onInit(){ | ||
Countly.pushTokenType(Countly.messagingMode.DEVELOPMENT); | ||
Countly.init("https://trinisoft.count.ly", "f0b2ac6919f718a13821575db28c0e2971e05ec5"); | ||
// Countly.init("https://try.count.ly","0e8a00e8c01395a0af8be0e55da05a404bb23c3e"); | ||
// ,"","5", "Rate us.", "How would you rate the app?", "Dismiss",false | ||
} | ||
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); | ||
}; | ||
eventWithSum(){ | ||
// example for event with sum | ||
var event = {"eventName":"Event With Sum","eventCount":1,"eventSum":"0.99"}; | ||
Countly.sendEvent(event); | ||
}; | ||
eventWithSegment(){ | ||
// example for event with segment | ||
var event = {"eventName":"Event With Segment","eventCount":1}; | ||
event.segments = {"Country" : "Turkey", "Age" : "28"}; | ||
Countly.sendEvent(event); | ||
event = {"eventName":"Event With Segment","eventCount":1}; | ||
event.segments = {"Country" : "France", "Age" : "38"}; | ||
Countly.sendEvent(event); | ||
}; | ||
eventWithSumAndSegment(){ | ||
// example for event with segment and sum | ||
var event = {"eventName":"Event With Sum And Segment","eventCount":1,"eventSum":"0.99"}; | ||
event.segments = {"Country" : "Turkey", "Age" : "28"}; | ||
Countly.sendEvent(event); | ||
event = {"eventName":"Event With Sum And Segment","eventCount":3,"eventSum":"1.99"}; | ||
event.segments = {"Country" : "France", "Age" : "38"}; | ||
Countly.sendEvent(event); | ||
}; | ||
// TIMED EVENTS | ||
startEvent(){ | ||
Countly.startEvent("timedEvent"); | ||
setTimeout(function(){ | ||
Countly.endEvent("timedEvent"); | ||
},1000); | ||
}; | ||
/* | ||
setTimeout may not work correctly if you are attached to Chrome Debugger. | ||
for workaround see: https://github.com/facebook/react-native/issues/9436 | ||
*/ | ||
timedEventWithSum(){ | ||
// Event with sum | ||
Countly.startEvent("timedEventWithSum"); | ||
var event = { | ||
"eventName": "timedEventWithSum", | ||
"eventSum": "0.99" | ||
}; | ||
setTimeout(function(){ | ||
Countly.endEvent(event); | ||
},1000); | ||
}; | ||
timedEventWithSegment(){ | ||
// Event with segment | ||
Countly.startEvent("timedEventWithSegment"); | ||
var event = { | ||
"eventName": "timedEventWithSegment" | ||
}; | ||
event.segments = { | ||
"Country": "Germany", | ||
"Age": "32" | ||
}; | ||
setTimeout(function(){ | ||
Countly.endEvent(event); | ||
},1000); | ||
}; | ||
timedEventWithSumAndSegment(){ | ||
// Event with Segment, sum and count | ||
Countly.startEvent("timedEventWithSumAndSegment"); | ||
var event = { | ||
"eventName": "timedEventWithSumAndSegment", | ||
"eventCount": 1, | ||
"eventSum": "0.99" | ||
}; | ||
event.segments = { | ||
"Country": "India", | ||
"Age": "21" | ||
}; | ||
setTimeout(function(){ | ||
Countly.endEvent(event); | ||
},1000); | ||
}; | ||
// TIMED EVENTS | ||
userData_setProperty(){ | ||
Countly.userData.setProperty("setProperty", "keyValue"); | ||
}; | ||
userData_increment(){ | ||
Countly.userData.setProperty("increment", 5); | ||
Countly.userData.increment("increment"); | ||
}; | ||
userData_incrementBy(){ | ||
Countly.userData.setProperty("incrementBy", 5); | ||
Countly.userData.incrementBy("incrementBy", 10); | ||
}; | ||
userData_multiply(){ | ||
Countly.userData.setProperty("multiply", 5); | ||
Countly.userData.multiply("multiply", 20); | ||
}; | ||
userData_saveMax(){ | ||
Countly.userData.setProperty("saveMax", 5); | ||
Countly.userData.saveMax("saveMax", 100); | ||
}; | ||
userData_saveMin(){ | ||
Countly.userData.setProperty("saveMin", 5); | ||
Countly.userData.saveMin("saveMin", 50); | ||
}; | ||
userData_setOnce(){ | ||
Countly.userData.setOnce("setOnce", 200); | ||
}; | ||
userData_pushUniqueValue(){ | ||
Countly.userData.pushUniqueValue("type", "morning"); | ||
}; | ||
userData_pushValue(){ | ||
Countly.userData.pushValue("type", "morning"); | ||
}; | ||
userData_pullValue(){ | ||
Countly.userData.pullValue("type", "morning"); | ||
}; | ||
onRegisterDevice(){ | ||
// Countly.initMessaging('403185924621', Countly.TEST); | ||
} | ||
changeDeviceId(){ | ||
Countly.changeDeviceId('02d56d66-6a39-482d-aff0-d14e4d5e5fda'); | ||
}; | ||
enableParameterTamperingProtection(){ | ||
Countly.enableParameterTamperingProtection("salt"); | ||
}; | ||
setRequiresConsent(){ | ||
Countly.setRequiresConsent(true); | ||
} | ||
giveEventsConsent(){ | ||
Countly.giveConsent("events"); | ||
}; | ||
removeEventsConsent(){ | ||
Countly.removeConsent("events"); | ||
}; | ||
giveMultipleConsent(){ | ||
Countly.giveConsent(["events", "views", "star-rating", "crashes", "invalidFeatureName"]); | ||
}; | ||
removeMultipleConsent(){ | ||
Countly.removeConsent(["events", "views"]); | ||
}; | ||
giveAllConsent(){ | ||
Countly.giveAllConsent(); | ||
}; | ||
removeAllConsent(){ | ||
Countly.removeAllConsent(); | ||
}; | ||
remoteConfigUpdate(){ | ||
Countly.remoteConfigUpdate(function(data){ | ||
console.log(data); | ||
}); | ||
}; | ||
updateRemoteConfigForKeysOnly(){ | ||
Countly.updateRemoteConfigForKeysOnly(["test1"],function(data){ | ||
console.log(data); | ||
}); | ||
}; | ||
updateRemoteConfigExceptKeys(){ | ||
Countly.updateRemoteConfigExceptKeys(["test1"],function(data){ | ||
console.log(data); | ||
}); | ||
}; | ||
getRemoteConfigValueForKeyBoolean(){ | ||
Countly.getRemoteConfigValueForKey("booleanValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyFloat(){ | ||
Countly.getRemoteConfigValueForKey("floatValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyInteger(){ | ||
Countly.getRemoteConfigValueForKey("integerValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyString(){ | ||
Countly.getRemoteConfigValueForKey("stringValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
getRemoteConfigValueForKeyJSON(){ | ||
Countly.getRemoteConfigValueForKey("jsonValue", function(data){ | ||
console.log(data); | ||
}); | ||
} | ||
remoteConfigClearValues(){ | ||
Countly.remoteConfigClearValues(); | ||
}; | ||
setLocation(){ | ||
var countryCode = "us"; | ||
var city = "Houston"; | ||
var latitude = "29.634933"; | ||
var longitude = "-95.220255"; | ||
var ipAddress = "103.238.105.167"; | ||
Countly.setLocation(countryCode, city, latitude + "," + longitude, ipAddress); | ||
}; | ||
disableLocation(){ | ||
Countly.disableLocation(); | ||
}; | ||
setupPush(){ | ||
Countly.askForNotificationPermission(); | ||
// console.log('setupPush'); | ||
// 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, | ||
// }); | ||
} | ||
enableLogging(){ | ||
Countly.enableLogging(); | ||
}; | ||
disableLogging(){ | ||
Countly.disableLogging(); | ||
}; | ||
setStarRatingDialogTexts(){ | ||
Countly.setStarRatingDialogTexts(); | ||
}; | ||
showStarRating(){ | ||
Countly.showStarRating(); | ||
}; | ||
showFeedbackPopup(){ | ||
Countly.showFeedbackPopup("5e4254507975d006a22535fc", "Submit"); | ||
} | ||
enableCrashReporting(){ | ||
Countly.enableCrashReporting(); | ||
}; | ||
addCrashLog(){ | ||
Countly.addCrashLog("My crash log in string."); | ||
}; | ||
addLogException(){ | ||
Countly.addCrashLog("User Performed Step A"); | ||
setTimeout(function(){ | ||
Countly.addCrashLog("User Performed Step B"); | ||
},1000); | ||
setTimeout(function(){ | ||
Countly.addCrashLog("User Performed Step C"); | ||
try { | ||
var a = {}; | ||
var x = a.b.c; // this will create error. | ||
} catch (error) { | ||
setTimeout(function(){ | ||
var stack = error.stack.toString(); | ||
Countly.logException(stack, true, {"_facebook_version": "0.0.1"}); | ||
},1000); | ||
} | ||
},1000); | ||
}; | ||
logException(){ | ||
Countly.logException(); | ||
} | ||
setEventSendThreshold(){ | ||
Countly.setEventSendThreshold("3"); | ||
} | ||
/* | ||
initNative(){ | ||
Countly.initNative(); | ||
}; | ||
testCrash(){ | ||
Countly.testCrash(); | ||
} | ||
*/ | ||
test(){ | ||
this.onInit(); | ||
this.onStart(); | ||
this.basicEvent(); | ||
this.eventWithSum(); | ||
this.eventWithSegment(); | ||
this.eventWithSumAndSegment(); | ||
this.startEvent(); | ||
this.onSendUserData(); | ||
this.userData_setProperty(); | ||
this.userData_increment(); | ||
this.userData_incrementBy(); | ||
this.userData_multiply(); | ||
this.userData_saveMax(); | ||
this.userData_saveMin(); | ||
this.userData_setOnce(); | ||
// this.changeDeviceId(); | ||
this.enableParameterTamperingProtection(); | ||
} | ||
render() { | ||
return ( | ||
<ScrollView > | ||
<View style={{ justifyContent: 'center', alignItems: 'center', margin: 20 }}> | ||
<Image source={{uri: 'https://count.ly/images/logos/countly-logo.png'}} style={ {width: 144, height: 42} } onError={(e) => console.log(e.nativeEvent.error) }/> | ||
<Text style={[{fontSize:24, textAlign: 'center'}]}>React Native Demo App</Text> | ||
</View> | ||
<Button onPress={() => navigate('PageOne')} title="Go to Page One"></Button> | ||
< Button onPress = { this.test } title = "Test" color = "#1b1c1d"> </Button> | ||
< 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> | ||
<Text style={[{textAlign: 'center'}]}>Events Start</Text> | ||
< Button onPress = { this.basicEvent } title = "Basic Events" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.eventWithSum } title = "Event with Sum" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.eventWithSegment } title = "Event with Segment" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.eventWithSumAndSegment } title = "Even with Sum and Segment" color = "#841584"> </Button> | ||
< Button onPress = { this.startEvent } title = "Timed event" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.timedEventWithSum } title = "Timed events with Sum" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.timedEventWithSegment } title = "Timed events with Segment" color = "#e0e0e0"> </Button> | ||
< Button onPress = { this.timedEventWithSumAndSegment } title = "Timed events with Sum and Segment" color = "#e0e0e0"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>Events End</Text> | ||
<Text style={[{textAlign: 'center'}]}>2017</Text> | ||
<Text style={[{textAlign: 'center'}]}>User Methods Start</Text> | ||
< Button onPress = { this.onSendUserData } title = "Send Users Data" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_setProperty } title = "UserData.setProperty" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_increment } title = "UserData.increment" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_incrementBy } title = "UserData.incrementBy" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_multiply } title = "UserData.multiply" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_saveMax } title = "UserData.saveMax" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_saveMin } title = "UserData.saveMin" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_setOnce } title = "UserData.setOnce" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_pushUniqueValue } title = "UserData.pushUniqueValue" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_pushValue } title = "UserData.pushValue" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.userData_pullValue } title = "UserData.pullValue" color = "#00b5ad"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>User Methods End</Text> | ||
<Text style={[{textAlign: 'center'}]}>Other Methods Start</Text> | ||
< Button onPress = { function(){Countly.recordView("HomePage")} } title = "Record View: 'HomePage'" color = "#e0e0e0"> </Button> | ||
< Button onPress = { function(){Countly.recordView("Dashboard")} } title = "Record View: 'Dashboard'" color = "#e0e0e0"> </Button> | ||
< Button onPress={this.enableLogging} title='Enable Logging' color='#00b5ad' /> | ||
< Button onPress={this.disableLogging} title='Disable Logging' color='#00b5ad' /> | ||
< Text style={[{ textAlign: 'center' }]}>Push Notification Start</Text> | ||
< Button onPress={this.setupPush} title='Register Device' color='#00b5ad' /> | ||
< Button onPress={this.changeDeviceId} title='Change Device ID' color='#00b5ad' /> | ||
< Text style={[{ textAlign: 'center' }]}>Push Notification End</Text> | ||
< Button onPress = { this.enableParameterTamperingProtection } title = "Enable Parameter Tapmering Protection" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.setRequiresConsent } title = "Init Consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.giveEventsConsent } title = "Give events consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.removeEventsConsent } title = "Remove events consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.giveMultipleConsent } title = "Give multiple consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.removeMultipleConsent } title = "Remove multiple consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.giveAllConsent } title = "Give all Consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.removeAllConsent } title = "Remove all Consent" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.setLocation } title = "Set Location" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.disableLocation } title = "Disable Location" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.remoteConfigUpdate } title = "Update Remote Config" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.updateRemoteConfigForKeysOnly } title = "Update Remote Config with Keys Only" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.updateRemoteConfigExceptKeys } title = "Update Remote Config Except Keys" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyBoolean } title = "Boolean Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyFloat } title = "Float Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyInteger } title = "Integer Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyString } title = "String Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.getRemoteConfigValueForKeyJSON } title = "JSON Test" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.remoteConfigClearValues } title = "Clear remote config cache" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.showStarRating } title = "Show Star Rating Model" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.showFeedbackPopup } title = "Show FeedBack Model" color = "#00b5ad"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>Other Methods End</Text> | ||
<Text style={[{textAlign: 'center'}]}>Crash Event start</Text> | ||
< Button onPress = { this.enableCrashReporting } title = "Enable Crash Reporting" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.addCrashLog } title = "Add Crash Log" color = "#00b5ad"> </Button> | ||
<Text style={[{textAlign: 'center'}]}>Crash Event End</Text> | ||
< Button onPress = { this.eventSendThreshold } title = "Set Event Threshold" color = "#00b5ad"> </Button> | ||
{/* | ||
< Button onPress = { this.initNative } title = "Init Native" color = "#00b5ad"> </Button> | ||
< Button onPress = { this.testCrash } title = "Test Native Crash" color = "crimson"> </Button> | ||
*/} | ||
</ScrollView> | ||
); | ||
} | ||
} | ||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
welcome: { | ||
fontSize: 20, | ||
textAlign: 'center', | ||
margin: 10, | ||
}, | ||
instructions: { | ||
textAlign: 'center', | ||
color: '#333333', | ||
marginBottom: 5, | ||
}, | ||
}); |
@@ -0,23 +1,83 @@ | ||
# iOS Push Notification Documentation | ||
### Using Example App | ||
Please visit [Countly React Native documentation page](https://resources.count.ly/docs/react-native-bridge) for further details. | ||
``` | ||
react-native init DemoProject # Create a new project | ||
Note: This documentation assumes, that you have created necessary certficate, have proper app bundle id. | ||
cd DemoProject # Go to that directory | ||
cp <PATH_TO>/App.js . # Copy App.js here into your new react project | ||
STEP 1: Make sure you have proper app bundle id and team selected. | ||
# Include SDK | ||
npm install --save https://github.com/Countly/countly-sdk-react-native-bridge.git | ||
react-native link countly-sdk-react-native-bridge | ||
STEP 2: Add Capabilities | ||
1. Push Notification | ||
2. Background Mode - Remote Notifications | ||
Go into your AwesomeProject/ios dir and open AwesomeProject.xcworkspace workspace. Select the top project "AwesomeProject" ans select the "Signing & Capabilities" tab. Add a 2 new Capabilities using "+" button: | ||
Background Mode capability and tick Remote Notifications. | ||
Push Notifications capability | ||
# In a new terminal | ||
adb reverse tcp:8081 tcp:8081 # Link Android port for development server | ||
npm start # Start development server | ||
STEP 3: Place below code in there respective files. | ||
# In root of DemoProject | ||
react-native run-android # OR # Run the android project | ||
react-native run-ios # Run the iOS project | ||
### AppDelegate.m | ||
Add header file | ||
`#import "CountlyReactNative.h"` | ||
`#import <UserNotifications/UserNotifications.h>` | ||
``` | ||
Before `@end` add these method | ||
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{ | ||
NSLog(@"didReceiveNotificationResponse"); | ||
NSDictionary *notification = response.notification.request.content.userInfo; | ||
[CountlyReactNative onNotification: notification]; | ||
completionHandler(); | ||
} | ||
//Called when a notification is delivered to a foreground app. | ||
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler | ||
{ | ||
NSLog(@"didReceiveNotificationResponse"); | ||
NSDictionary *userInfo = notification.request.content.userInfo; | ||
[CountlyReactNative onNotification: userInfo]; | ||
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); | ||
} | ||
# Rich Push Notification | ||
STEP 1: Creating Notification Service Extension | ||
Editor -> Add Target -> | ||
Make sure `ios` is selected | ||
Make sure `Notification Service Extension` is selected | ||
Click `Next` | ||
Enter Product Name e.g. `CountlyNSE` | ||
Language `Objective-C` | ||
Click `Finish` | ||
It will ask for a modal / popup `Activate “CountlyNSE” scheme?` | ||
Choose `Cancel` | ||
STEP 2: Adding Compile Source | ||
Under `TARGETS` select `CountlyNSE` | ||
Select `Build Phases` | ||
Expand `Compile Sources` | ||
Drag and Drop `CountlyNotificationService.h` and `CountlyNotificationService.m` file | ||
Note: You may also find this file in `Xcode` under `Pods(Project) -> Pods(Folder) -> Countly` | ||
Note: You may also find this file in `Finder` under `AwesomeProject/ios/Pods/Countly` | ||
Note: You may also find this file in `Xcode` under `AwesomeProject(Project) -> Libraries(Folder) -> countly-sdk-react-native-bridge(Project)->src(Folder)` | ||
Note: You may also find this file in `Finder` under `node_modules/countly-sdk-react-native-bridge/ios/Pods/Countly` | ||
STEP 3: Updating NotificationService file | ||
Under `AwesomeProject(Project) -> CountlyNSE(Folder) -> NotificationService.m` | ||
Add import header `#import "CountlyNotificationService.h"` | ||
Add the following line at the end of `didReceiveNotificationRequest:withContentHandler:` | ||
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler | ||
{ | ||
self.contentHandler = contentHandler; | ||
self.bestAttemptContent = [request.content mutableCopy]; | ||
//delete existing template code, and add this line | ||
[CountlyNotificationService didReceiveNotificationRequest:request withContentHandler:contentHandler]; | ||
} | ||
Note: Please make sure you configure App Transport Security setting in extension's Info.plist file also, just like the main application. Otherwise media attachments from non-https sources can not be loaded. | ||
Note: Please make sure you check Deployment Target version of extension target is 10, not 10.3 (or whatever minor version Xcode set automatically). Otherwise users running iOS versions lower than Deployment Target value can not get rich push notifications. | ||
Note: To send push messages to applications that are Debug build use Countly.messagingMode.DEVELOPMENT, for App Store built ones use Countly.messagingMode.PRODUCTION, and for TestFlight/Ad Hoc builds use Countly.messagingMode.ADHOC. |
{ | ||
"name": "countly-sdk-react-native-bridge", | ||
"version": "19.8.6", | ||
"version": "20.4.0", | ||
"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
Sorry, the diff of this file is not supported yet
38
227748
1990