Skip to content

Commit e6fea00

Browse files
author
Christof Kost
committed
put everything up to make it work with older version of flutter_apns_only
1 parent b0553c0 commit e6fea00

File tree

6 files changed

+68
-20
lines changed

6 files changed

+68
-20
lines changed

example/pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ packages:
124124
path: "../flutter_apns"
125125
relative: true
126126
source: path
127-
version: "1.5.1"
127+
version: "1.5.2"
128128
flutter_apns_only:
129-
dependency: "direct overridden"
129+
dependency: transitive
130130
description:
131-
path: "../flutter_apns_only"
132-
relative: true
133-
source: path
134-
version: "1.5.0-dev.1"
131+
name: flutter_apns_only
132+
url: "https://pub.dartlang.org"
133+
source: hosted
134+
version: "1.5.0"
135135
flutter_local_notifications:
136136
dependency: "direct main"
137137
description:

example/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name: flutter_apns_example
22
description: Demonstrates how to use the flutter_apns plugin.
3-
publish_to: 'none'
3+
publish_to: "none"
44
version: 1.0.0+1
55

66
environment:
7-
sdk: '>=2.12.0 <3.0.0'
7+
sdk: ">=2.12.0 <3.0.0"
88

99
dependencies:
1010
flutter:
1111
sdk: flutter
1212

13-
cupertino_icons: ^1.0.2
13+
cupertino_icons: ^1.0.2
1414
path_provider: ^2.0.1
1515

1616
flutter_local_notifications: ^5.0.0-nullsafety.1
@@ -24,7 +24,7 @@ flutter:
2424
uses-material-design: true
2525

2626
dependency_overrides:
27-
flutter_apns_only:
28-
path: ../flutter_apns_only
27+
# flutter_apns_only:
28+
# path: ../flutter_apns_only
2929
flutter_apns:
30-
path: ../flutter_apns
30+
path: ../flutter_apns

flutter_apns/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
### 1.5.2
22
* update firebase dependencies
3-
* (#78) Do not hide push notification when opening app
4-
* Add readme: how to run example app
3+
* Add readme: how to run example app in iOS
54
### 1.5.1
65
* (#58) fix unable to build android (update firebase dependencies)
76
### 1.5.0-dev.1

flutter_apns/README.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# apns
22

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.
44

55
## Why this plugin was made?
66

77
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.
88

99
## Usage
1010
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+
1213
3. Add the following lines to the `didFinishLaunchingWithOptions` method in the AppDelegate.m/AppDelegate.swift file of your iOS project
1314

1415
Objective-C:
@@ -38,7 +39,7 @@ connector.configure(
3839
);
3940
connector.requestNotificationPermissions()
4041
```
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)).
4243

4344
## Additional APNS features:
4445
### Displaying notification while in foreground
@@ -103,7 +104,7 @@ If you want to use firebase, but not firebase messaging, add this configuration
103104
<false/>
104105
```
105106

106-
## flutter_apns_only - APNS without firebase
107+
## flutter_apns_only - APNS without firebase
107108
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:
108109

109110
```plist
@@ -159,3 +160,50 @@ import Flutter
159160

160161
@end
161162
```
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+
![](example/assets/Xcode_setup.png?raw=true)
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+
![](example/assets/register_app.png?raw=true)
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+
![](example/assets/select_capability.png?raw=true)
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+
![](example/assets/push_notification_setup.png?raw=true)
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+
![](example/assets/keychain.png?raw=true)
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).

flutter_apns/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_apns
22
description: APNS push notification plugin. Uses firebase_messaging on Android, but replaces it on iOS with custom implementation.
3-
version: 1.5.2
3+
version: 1.5.3
44
homepage: https://github.com/mwaylabs/flutter-apns
55

66
environment:
@@ -12,7 +12,7 @@ dependencies:
1212
sdk: flutter
1313
firebase_core: ^1.11.0
1414
firebase_messaging: ^11.2.5
15-
flutter_apns_only: ^1.5.2
15+
flutter_apns_only: ^1.5.0
1616

1717
dev_dependencies:
1818
flutter_test:

flutter_apns_only/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.5.2
22

33
* upgraded together with flutter_apns
4+
* (#78) Do not hide push notification when opening app
45

56
## 1.5.0-dev.1
67

0 commit comments

Comments
 (0)