Skip to content

Commit 8e1b9bd

Browse files
cpetrovChristian Petrov
authored andcommitted
Introduce requestPermissions() JS method
Also document the requestPermissions() feature. Change-Id: I0568f0a0b810687ac2017b50ea6f2f8a1e7579e9
1 parent 0835ea4 commit 8e1b9bd

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

doc/cloud-messaging.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,7 @@ All `Messaging` properties are read only.
153153
##### `resetInstanceId()`
154154

155155
* Invalidates the current `instanceId` and creates a new one asynchronously. To be notified when a new `instanceId` is available you should listen for the `instanceIdChanged` event. Resetting the `instanceId` also resets the associated registration `token`. A `tokenChanged` event will be fired once a new token is available.
156+
157+
##### `requestPermissions()` (iOS-only)
158+
159+
* Shows the system dialog for requesting permissions for the first time. Does nothing if the permissions have been requested already. The dialog will only be shown again when calling this method if the app has been uninstalled for at least a day or if the device has been restored (see ["Resetting the Push Notifications Permissions Alert on iOS"](https://developer.apple.com/library/archive/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG42) for more information).

example/src/pages/messaging.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {Composite, Page, ScrollView, TextView} = require('tabris');
1+
const {device, Button, Composite, Page, ScrollView, TextView} = require('tabris');
22
const Card = require('../widgets/Card');
33
const FlatButton = require('../widgets/FlatButton');
44
const res = require('../resources');
@@ -67,6 +67,14 @@ module.exports = class MessagingPage extends Page {
6767
}).on('tap', () => firebase.Messaging.resetInstanceId())
6868
.appendTo(instanceIdCard);
6969

70+
if (device.platform === 'iOS') {
71+
new Button({
72+
top: ['prev()', MARGIN_SMALL], centerX: 0,
73+
text: 'Request permissions'
74+
}).on('tap', () => firebase.Messaging.requestPermissions())
75+
.appendTo(scrollView);
76+
}
77+
7078
new Composite({top: 'prev()', height: MARGIN}).appendTo(scrollView);
7179

7280
if (firebase.Messaging.launchData) {

www/Messaging.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ Messaging.prototype.resetInstanceId = function() {
2525
return this;
2626
}
2727

28+
Messaging.prototype.requestPermissions = function() {
29+
if (tabris.device.platform === 'iOS') {
30+
this._nativeCall('requestPermissions');
31+
} else {
32+
console.warn('requestPermissions() is only supported on iOS.');
33+
}
34+
return this;
35+
}
36+
2837
tabris.NativeObject.defineProperties(Messaging.prototype, {
2938
instanceId: {type: 'string', nocache: true, access: readOnly},
3039
token: {type: 'string', nocache: true, access: readOnly},

0 commit comments

Comments
 (0)