Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
StyleSheet,
Text,
Pressable,
ScrollView,
View,
DeviceEventEmitter,
} from 'react-native';
Expand Down Expand Up @@ -49,7 +50,12 @@ export const App = (): React.Node => {
onLocalNotification,
);

PushNotificationIOS.requestPermissions().then(
PushNotificationIOS.requestPermissions({
alert: true,
badge: true,
sound: true,
critical: true,
}).then(
(data) => {
console.log('PushNotificationIOS.requestPermissions', data);
},
Expand Down Expand Up @@ -130,6 +136,20 @@ export const App = (): React.Node => {
});
};

const addCriticalNotificationRequest = () => {
PushNotificationIOS.addNotificationRequest({
id: 'critical',
title: 'Critical Alert',
subtitle: 'subtitle',
body: 'This is a critical alert',
category: 'test',
threadId: 'thread-id',
isCritical: true,
fireDate: new Date(new Date().valueOf() + 2000),
repeats: true,
});
};

const addMultipleRequests = () => {
PushNotificationIOS.addNotificationRequest({
id: 'test-1',
Expand Down Expand Up @@ -298,7 +318,7 @@ export const App = (): React.Node => {
};

return (
<View style={styles.container}>
<ScrollView contentContainerStyle={styles.container}>
<Button onPress={sendNotification} label="Send fake notification" />
<Button
onPress={sendLocalNotification}
Expand All @@ -316,6 +336,10 @@ export const App = (): React.Node => {
onPress={addNotificationRequest}
label="Add Notification Request"
/>
<Button
onPress={addCriticalNotificationRequest}
label="Add Critical Notification Request (only works with Critical Notification entitlement)"
/>
<Button
onPress={addMultipleRequests}
label="Add Multiple Notification Requests"
Expand Down Expand Up @@ -353,15 +377,13 @@ export const App = (): React.Node => {
<Button onPress={showPermissions} label="Show enabled permissions" />
<Text>{JSON.stringify(permissions)}</Text>
</View>
</View>
</ScrollView>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
flexGrow: 1,
backgroundColor: '#F5FCFF',
},
button: {
Expand Down
1 change: 0 additions & 1 deletion example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
54E1C96C0B8E8387A67DA085 /* Pods-example-exampleTests.debug.xcconfig */,
3061B48EE839E0AAF1DF8A70 /* Pods-example-exampleTests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,52 @@
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
6 changes: 4 additions & 2 deletions ios/RNCPushNotificationIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
if ([RCTConvert BOOL:permissions[@"sound"]]) {
types |= UNAuthorizationOptionSound;
}
if ([RCTConvert BOOL:permissions[@"critical"]]) {
types |= UNAuthorizationOptionCriticalAlert;
if (@available(iOS 12, *)) {
if ([RCTConvert BOOL:permissions[@"critical"]]) {
types |= UNAuthorizationOptionCriticalAlert;
}
}
} else {
types = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound;
Expand Down
8 changes: 8 additions & 0 deletions js/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ export type NotificationRequest = {|
* Sets notification to be silent
*/
isSilent?: boolean,
/**
* Sets notification to be critical
*/
isCritical?: boolean,
/**
* The volume for the critical alert’s sound. Set this to a value between 0.0 (silent) and 1.0 (full volume).
*/
criticalSoundVolume?: number,
/**
* Optional data to be added to the notification
*/
Expand Down