This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npx create-react-app my-app | |
cd my-app | |
npm install react-intl --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install https://github.com/zo0r/react-native-push-notification --save | |
// For IOS | |
npm install https://github.com/react-native-community/react-native-push-notification-ios --save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, Button, Text } from 'react-native'; | |
import LocalNotificationService from '../../utils/LocalNotificationService'; | |
// Just init your project root one time. | |
LocalNotificationService.init(); | |
LocalNotificationService.configure(); | |
export default class App extends React.Component { | |
notify() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Button title="Notify Me" onPress={() => this.notify()} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notify() { | |
LocalNotificationService.sendLocalNotification('Notification Title', 'Notification Detail Content'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import LocalNotificationService: | |
import LocalNotificationService from '../utils/LocalNotificationService'; | |
// Init LocalNotificationService | |
// Just init your project root one time. | |
LocalNotificationService.init(); | |
LocalNotificationService.configure(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PushNotification from 'react-native-push-notification'; | |
import { Platform } from 'react-native'; | |
export default class LocalNotificationService { | |
static init() { | |
LocalNotificationService.onNotification = notification => { | |
if (Platform.OS === 'android' && notification.subject != null && notification.subject !== '') { | |
PushNotification.localNotification({ | |
title: notification.subject, | |
message: notification.body, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static cancelAll() { | |
PushNotification.cancelAllLocalNotifications(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static sendLocalNotification(title, message) { | |
PushNotification.localNotification({ | |
title, // (optional) // Your content title | |
message, // (required) // Your content message. It is required for notification. | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static configure() { | |
PushNotification.configure({ | |
onNotification: notification => { | |
if (LocalNotificationService.onNotification) { | |
LocalNotificationService.onNotification(notification); | |
} | |
}, | |
requestPermissions: true, | |
popInitialNotification: true, | |
}); |
NewerOlder