|
1 | 1 | # apns
|
2 | 2 |
|
3 |
| -Plugin to implement APNS push notifications on iOS and Firebase on Android. |
| 3 | +Plugin to implement APNS push notifications on iOS and Firebase on Android. |
4 | 4 |
|
5 | 5 | ## Why this plugin was made?
|
6 | 6 |
|
7 | 7 | Currently, the only available push notification plugin is `firebase_messaging`. This means that, even on iOS, you will need to setup firebase and communicate with Google to send push notification. This plugin solves the problem by providing native APNS implementation while leaving configured Firebase for Android.
|
8 | 8 |
|
9 | 9 | ## Usage
|
10 | 10 | 1. Configure firebase on Android according to instructions: https://pub.dartlang.org/packages/firebase_messaging.
|
11 |
| -2. On iOS, make sure you have correctly configured your app to support push notifications, and that you have generated certificate/token for sending pushes. |
| 11 | +2. On iOS, make sure you have correctly configured your app to support push notifications, and that you have generated certificate/token for sending pushes. For more infos see section [How to run example app on iOS](#how-to-run-example-app-on-ios) |
| 12 | + |
12 | 13 | 3. Add the following lines to the `didFinishLaunchingWithOptions` method in the AppDelegate.m/AppDelegate.swift file of your iOS project
|
13 | 14 |
|
14 | 15 | Objective-C:
|
@@ -38,7 +39,7 @@ connector.configure(
|
38 | 39 | );
|
39 | 40 | connector.requestNotificationPermissions()
|
40 | 41 | ```
|
41 |
| -6. Build on device and test your solution using Firebase Console and NWPusher app. |
| 42 | +6. Build on device and test your solution using Firebase Console (Android) and CURL (iOS, see [How to run example app on iOS](#how-to-run-example-app-on-ios)). |
42 | 43 |
|
43 | 44 | ## Additional APNS features:
|
44 | 45 | ### Displaying notification while in foreground
|
@@ -103,7 +104,7 @@ If you want to use firebase, but not firebase messaging, add this configuration
|
103 | 104 | <false/>
|
104 | 105 | ```
|
105 | 106 |
|
106 |
| -## flutter_apns_only - APNS without firebase |
| 107 | +## flutter_apns_only - APNS without firebase |
107 | 108 | If only care about apns - use flutter_apns_only plugin. It does not depend on firebase. To ensure no swizzling (which is needed by original plugin to disable firebase) takes place, add this configuration entry in your Info.plist:
|
108 | 109 |
|
109 | 110 | ```plist
|
@@ -159,3 +160,50 @@ import Flutter
|
159 | 160 |
|
160 | 161 | @end
|
161 | 162 | ```
|
| 163 | +## How to run example app on iOS |
| 164 | +Setting up push notifications on iOS can be tricky since there is no way to permit Apple Push Notification Service (APNS) which requires a complicated certificate setup. The following guide describes a step by step approach to send push notifications from your Mac to an iPhone utilizing the example app of this package. This guide only describes debug environment setup. |
| 165 | +
|
| 166 | +1. Open example ios folder with Xcode |
| 167 | +2. Select Runner -> Signing & Capabilities |
| 168 | +3. Select your development team and add a globally unique bundle identifier. The one on the picture is already occupied: |
| 169 | +  |
| 170 | +4. Go to https://developer.apple.com/account/resources/identifiers/list/bundleId and press on the plus button |
| 171 | +5. Select "App IDs" and press continue |
| 172 | +  |
| 173 | +6. Select type "App" |
| 174 | +7. Select "App ID Prefix" which should be same as "Team ID" |
| 175 | +8. Enter description and bundle ID. The latter one needs to be the same as the bundle ID specified in 3. |
| 176 | +9. Select push notification capability |
| 177 | +  |
| 178 | +11. Press on "Continue" and then on "Register" |
| 179 | +12. Go to https://developer.apple.com/account/resources/certificates and add a new certificate by pressing on the plus-button. |
| 180 | +13. Select 'Apple Push Notification service SSL (Sandbox & Production)' |
| 181 | +  |
| 182 | +14. Select the app ID that you hav defined in point 4.-10. |
| 183 | +15. Select a Certificate Signing Request (CSR) file. See https://help.apple.com/developer-account/#/devbfa00fef7 on how to create this certificate |
| 184 | +16. When having finished, download the newly created Apple Push Services certificate |
| 185 | +17. Add certificate to your local keychain by opening the newly downloaded file |
| 186 | +18. Press on "login" on the upper left corner of your keychain window and select the tab "My Certificates" |
| 187 | +  |
| 188 | +19. Right click on the Apple-Push-Services-certificate and export it as .p12-file |
| 189 | +20. Convert p12-file to pem-file by following command. Please consider that "flutterApns" needs to be replaced by your respective certificate name.<br> |
| 190 | + [More info](https://stackoverflow.com/questions/1762555/creating-pem-file-for-apns) |
| 191 | + ``` |
| 192 | + openssl pkcs12 -in flutterApns.p12 -out flutterApns.pem -nodes -clcerts |
| 193 | + ``` |
| 194 | +21. Start example app on physical iPhone device from Xcode or your favorite IDE. |
| 195 | +22. Device token gets automatically printed when application was able to retrieve push token from APNS. This happens after accepting notification permission prompt. |
| 196 | +23. Send the following CURL from you development Mac. You can execute CURLs by copy-pasting them into Terminal and hit enter.<br> |
| 197 | + [More info](https://gist.github.com/greencoder/16d1f8d7b0fed5b49cf64312ce2b72cc) |
| 198 | + ```curl |
| 199 | + curl -v \ |
| 200 | + -d '{"aps":{"alert":"<your_message>","badge":2}}' \ |
| 201 | + -H "apns-topic: <bundle_identifier_of_registered_app>" \ |
| 202 | + -H "apns-priority: 10" \ |
| 203 | + --http2 \ |
| 204 | + --cert <file_path_to_downloaded_sigxwned_and_converted_certificate>.pem \ |
| 205 | + https://api.development.push.apple.com/3/device/<device_token> |
| 206 | + ``` |
| 207 | +24. A push notification does appear if the example app is in background. |
| 208 | +
|
| 209 | +When not utilizing the example app, you need to additionally [setup push notification capability inside Xcode](https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns) and add the code mentioned in [usage](#usage). |
0 commit comments