Skip to content

Instantly share code, notes, and snippets.

View ShanikaNishadhi's full-sized avatar

Shanika Wickramasinghe ShanikaNishadhi

View GitHub Profile
import PushNotificationIOS from '@react-native-community/push-notification-ios'
const showNotifications = (title, message) => {
PushNotificationIOS.presentLocalNotification({
alertTitle: title,
alertBody: message,
});
};
const handleScheduleNotifications = (title, message) => {
import PushNotification from 'react-native-push-notification'
const showNotifications = (title, message) => {
PushNotification.localNotification({
title: title,
message: message,
});
};
const handleScheduleNotifications = (title, message) => {
import React from 'react';
import {View, Text, StyleSheet, TouchableOpacity} from 'react-native';
const App = () => {
return(
<View style={styles.container}>
<Text>Push Notifications</Text>
<TouchableOpacity activeOpacity={0.6}>
<View style={styles.button}>
<Text style={styles.buttonTitle}>Click me to get notification</Text>
module.exports = {
bracketSpacing: true,
...
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import PushNotification from 'react-native-push-notification';
import { Platform } from 'react-native';
AppRegistry.registerComponent(appName, () => App);
//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}
...
// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
...
...
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
<resources>
<color name="white">#FFF</color>
</resources>
<!-- Change the value to true to enable pop-up for in foreground on receiving remote notifications (for prevent duplicating while showing local notifications set this to false) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/>
<!-- or @android:color/{name} to use a standard color -->
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />