Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
Added VoIP Notifications support for iOS (#2194)
Browse files Browse the repository at this point in the history
* Ios VoIP Push feature

* VoIP feature bugs fixed

* VoIP JS connector

* VoIPPush feature included in the main PushPlugin class

* VoIP feature: Removed sources from config.xml

* VoIP feature: PushKit framework fixed in plugin.xml

* Update API.md

* Update PAYLOAD.md

* API.md suggestions modified

* PushPlugin.m pull request requested changes

* push.js reverted to previous commit

* PushPlugin.m removed unused code
  • Loading branch information
jlorente authored and macdonst committed Feb 22, 2018
1 parent e3a6417 commit 69e86d9
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 147 deletions.
23 changes: 23 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ All iOS boolean options can also be specified as `string`

Attribute | Type | Default | Description
--------- | ---- | ------- | -----------
`ios.voip` | `boolean` | `false` | Optional. If `true` the device will be set up to receive VoIP Push notifications and the other options will be ignored since VoIP notifications are silent notifications that should be handled in the "notification" event.
`ios.alert` | `boolean` | `false` | Optional. If `true` the device shows an alert on receipt of notification. **Note:** the value you set this option to the first time you call the init method will be how the application always acts. Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>`App Name`. This is normal iOS behaviour.
`ios.badge` | `boolean` | `false` | Optional. If `true` the device sets the badge number on receipt of notification. **Note:** the value you set this option to the first time you call the init method will be how the application always acts. Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>`App Name`. This is normal iOS behaviour.
`ios.sound` | `boolean` | `false` | Optional. If `true` the device plays a sound on receipt of notification. **Note:** the value you set this option to the first time you call the init method will be how the application always acts. Once this is set programmatically in the init method it can only be changed manually by the user in Settings>Notifications>`App Name`. This is normal iOS behaviour.
Expand Down Expand Up @@ -99,6 +100,28 @@ Make sure that the certificate you build with matches your `fcmSandbox` value.

> Note: The integration between GCM and APNS is a bit finicky. Personally, I feel it is much better to send pushes to Android using GCM and pushes to iOS using APNS which this plugin does support.
#### iOS VoIP Notifications

It is possible to receive VoIP Notifications in iOS that can execute the "notification" event also when the application is in background or closed.

This type of notifications consist only of payload data, so the developer is the responsible of handling the event and do whatever the aplication should do when receiving one of them. The cordova-plugin-local-notifications is a good complement for the VoIP feature.

In order to use the VoIP Notifications, you have to create a VoIP Services Certificate. There are a lot of tutorials on the web to achieve this. Once created, you must use this certificate in order to communicate with the APN Service.

To set up the VoIP Notification in ios do:
```javascript
const push = PushNotification.init({
ios: {
voip: true
}
});
```
Once set up the voip parameter to true, the rest of the options will be ignored.

The "hasPermission" success callback will return data.isEnabled to false since there is no need to approve to use this type of notifications.

The "finish" method has not use too when the VoIP notifications are enabled.

### Example

```javascript
Expand Down
11 changes: 11 additions & 0 deletions docs/PAYLOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [iOS Behaviour](#ios-behaviour)
- [Sound](#sound-1)
- [Background Notifications](#background-notifications-1)
- [VoIP Notifications](#voip-notifications)
- [Action Buttons](#action-buttons-1)
- [Action Buttons using GCM on iOS](#action-buttons-using-gcm-on-ios)
- [GCM and Additional Data](#gcm-and-additional-data)
Expand Down Expand Up @@ -1654,6 +1655,16 @@ push.on('notification', (data) => {

It is absolutely critical that you call `push.finish()` when you have successfully processed your background push data.

## VoIP Notifications

VoIP Notifications are a type of iOS notifications that are always received and handled also when the app is closed or in background and consist only of payload data, so the developer is the responsible of handling the event and do whatever the aplication should do when receiving one of them. The cordova-plugin-local-notifications is a good complement for the VoIP feature.

In order to maintain the plugin data transfer standard, the payload sent to aps maintains the same structure as the one of common notifications with the consideration that the notification will be always be silent independently of the params that you pass to it.

The `on('notification')` event handler will always be called excepting if Background App Refresh is disabled on the user's iOS device. (Settings > General > Background App Refresh).

In order to set up your application with this type of notifications, refer to the [API guide](API.md#ios-voip-notifications).

## Action Buttons

Your notification can include action buttons. For iOS 8+ you must setup the possible actions when you initialize the plugin:
Expand Down
4 changes: 3 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<config-file target="*-Info.plist" parent="UIBackgroundModes">
<array>
<string>remote-notification</string>
<string>voip</string>
</array>
</config-file>
<config-file target="*-Debug.plist" parent="aps-environment">
Expand All @@ -81,6 +82,7 @@
<header-file src="src/ios/AppDelegate+notification.h"/>
<header-file src="src/ios/PushPlugin.h"/>
<framework src="FirebaseMessaging" type="podspec" spec="~> 2.0.0"/>
<framework src="PushKit.framework" />
</platform>
<platform name="windows">
<hook type="after_plugin_install" src="hooks/windows/setToastCapable.js"/>
Expand All @@ -91,4 +93,4 @@
<preference name="WindowsToastCapable" value="true"/>
</config-file>
</platform>
</plugin>
</plugin>
5 changes: 5 additions & 0 deletions src/ios/PushPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#import <Foundation/Foundation.h>
#import <Cordova/CDV.h>
#import <Cordova/CDVPlugin.h>
#import <PushKit/PushKit.h>

@protocol GGLInstanceIDDelegate;
@protocol GCMReceiverDelegate;
Expand Down Expand Up @@ -68,6 +69,10 @@
- (void)didSendDataMessageWithID:(NSString *)messageID;
- (void)didDeleteMessagesOnServer;

// VoIP Features
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type;

// FCM Features
@property(nonatomic, assign) BOOL usesFCM;
@property(nonatomic, strong) NSNumber *fcmSandbox;
Expand Down
Loading

0 comments on commit 69e86d9

Please sign in to comment.