Skip to content

Commit 70e17fe

Browse files
committed
Add registerForProvisionalAuthorization method
* Add registerForProvisionalAuthorization() iOS support
1 parent 0a4ce2d commit 70e17fe

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

examples/RNOneSignalTS/src/OSButtons.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ class OSButtons extends React.Component<Props, State> {
7878
}
7979
);
8080

81+
const registerForProvisionalAuthorization = renderButtonView(
82+
"Register For Provisional Authorization",
83+
color,
84+
() => {
85+
loggingFunction("Register For Provisional Authorization with user response...");
86+
OneSignal.registerForProvisionalAuthorization(response => {
87+
loggingFunction(`User response: ${response}`);
88+
});
89+
}
90+
);
91+
8192
const locationShared = renderButtonView("is Location Shared", color, async () => {
8293
let appHasLocationShared = await OneSignal.isLocationShared();
8394
loggingFunction(`Application has location shared active: ${appHasLocationShared}`);
@@ -102,7 +113,10 @@ class OSButtons extends React.Component<Props, State> {
102113
}
103114
);
104115

105-
elements.push(subscribedButton, unsubscribeWhenNotificationsAreDisabledButton, locationShared, setLocationShared, promptLocationButton);
116+
elements.push(subscribedButton,
117+
unsubscribeWhenNotificationsAreDisabledButton,
118+
registerForProvisionalAuthorization,
119+
locationShared, setLocationShared, promptLocationButton);
106120

107121
if (Platform.OS === 'ios') {
108122
elements.push(promptForPush);

ios/RCTOneSignal/RCTOneSignalEventEmitter.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
279279
}];
280280
}
281281

282+
RCT_EXPORT_METHOD(registerForProvisionalAuthorization:(RCTResponseSenderBlock)callback) {
283+
[OneSignal registerForProvisionalAuthorization:^(BOOL accepted) {
284+
callback(@[@(accepted)]);
285+
}];
286+
}
287+
282288
RCT_EXPORT_METHOD(sendTag:(NSString *)key value:(NSString*)value) {
283289
[OneSignal sendTag:key value:value];
284290
}

src/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ declare module 'react-native-onesignal' {
180180
* @returns void
181181
*/
182182
promptForPushNotificationsWithUserResponse(handler?: (response: boolean) => void): void;
183+
184+
/**
185+
* Only applies to iOS (does nothing on Android as it always silently registers)
186+
* Request for Direct-To-History push notification authorization
187+
*
188+
* For more information: https://documentation.onesignal.com/docs/ios-customizations#provisional-push-notifications
189+
*
190+
* @param {(response:boolean)=>void} handler
191+
* @returns void
192+
*/
193+
registerForProvisionalAuthorization(handler?: (response: boolean) => void): void;
183194

184195
/**
185196
* Disable the push notification subscription to OneSignal.

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ export default class OneSignal {
9292
} else {
9393
console.log("promptForPushNotificationsWithUserResponse: this function is not supported on Android");
9494
}
95+
}
96+
97+
static registerForProvisionalAuthorization(handler) {
98+
if (!checkIfInitialized(RNOneSignal)) return;
99+
100+
if (Platform.OS === 'ios') {
101+
isValidCallback(handler);
102+
RNOneSignal.registerForProvisionalAuthorization(handler);
103+
} else {
104+
console.log("registerForProvisionalAuthorization: this function is not supported on Android");
105+
}
95106
}
96107

97108
static disablePush(disable) {

0 commit comments

Comments
 (0)