Skip to content

Instantly share code, notes, and snippets.

import PushNotification from 'react-native-push-notification';
import PushNotificationIOS from '@react-native-community/push-notification-ios';
import { AppState, Platform } from 'react-native';
import { checkNotifications, RESULTS } from 'react-native-permissions';
// BIIIIG WARNING: in iOS you'll get a token ONLY if you request permission for it.
// Therefore, a call for PushNotification.requestPermissions() is required.
// Android doesn't need the user's consent to send notifications, whereas iOS does
// but Android's user can still turn off notifications in the system settings
@arnaudambro
arnaudambro / AndroidManifest.xml
Created December 13, 2020 20:36
AndroidManifest.xml for setting up push notifications
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pushtest"> <!-- YOUR BUNDLE ID HERE -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
@arnaudambro
arnaudambro / Podfile
Created December 13, 2020 20:25
Podfile for asking push notifications permission
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'
target 'le_gratin' do
config = use_native_modules!
permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UNUserNotificationCenter.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
@property (nonatomic, strong) UIWindow *window;
@end
@arnaudambro
arnaudambro / electron-react-boilerplate error stacktrace cataline 32 bits
Created January 16, 2020 15:49
macOS Catalina doesn't support 32-bit executables and as result Wine cannot run Windows 32-bit applications too
yarn package-all
yarn run v1.21.1
$ yarn build && electron-builder build -mwl
$ concurrently "yarn build-main" "yarn build-renderer"
$ cross-env NODE_ENV=production webpack --config ./configs/webpack.config.main.prod.babel.js --colors
$ cross-env NODE_ENV=production webpack --config ./configs/webpack.config.renderer.prod.babel.js --colors
[0] Hash: 14f890f1e10c18274383
[0] Version: webpack 4.41.2
[0] Time: 3824ms
[0] Built at: 01/16/2020 4:43:50 PM
@arnaudambro
arnaudambro / App.js
Last active December 13, 2020 21:35
Listen to notifications
import React from 'react';
import { SafeAreaView, StyleSheet, View, Text, StatusBar, TouchableOpacity, Platform, Alert } from 'react-native';
import DeviceInfo from 'react-native-device-info';
import Notifications from './NotificationService'
class App extends React.Component {
constructor(props) {
super(props);
Notifications.init(this.handleRegister);
}
@arnaudambro
arnaudambro / App.js
Last active December 13, 2020 21:29
Set-up request notifications routes
import React from 'react';
import {SafeAreaView, StyleSheet, View, Text, StatusBar, TouchableOpacity, Platform} from 'react-native';
import Notifications from './NotificationService'
class App extends React.Component {
constructor(props) {
super(props);
Notifications.init(this.handleRegister);
}
@arnaudambro
arnaudambro / App.js
Last active December 13, 2020 21:36
Adding the notifications code
import React from 'react';
import {SafeAreaView, StyleSheet, View, Text, StatusBar, TouchableOpacity, Platform} from 'react-native';
import Notifications from './NotificationService'
class App extends React.Component {
constructor(props) {
super(props);
Notifications.init(this.handleRegister);
}
@arnaudambro
arnaudambro / AppDelegate.m
Last active December 13, 2020 20:15
Installation of react-native-notifications
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "UserNotifications/UserNotifications.h"
#import "RNCPushNotificationIOS.h"
#ifdef FB_SONARKIT_ENABLED
import React from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
StatusBar,
TouchableOpacity,
} from 'react-native';