Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-3642] A preview of an implementation of the location pushes. #1771

Merged
merged 37 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b7dad6a
A preview of an implementation of the location pushes.
maratal Jun 19, 2023
b636ba5
Additional `ARTPushRegistererDelegate` method for user's app could re…
maratal Jul 2, 2023
5c13ee3
Partial cherry pick from 2eaf0b46
lawrence-forooghian Jun 29, 2023
30fbf91
Removed "Activate Location Push" button.
maratal Jul 2, 2023
6a9df87
Made `deviceTokenString` a public utility method
maratal Jul 2, 2023
e257354
Updated example to display both default and location device tokens in…
maratal Jul 2, 2023
8b7cdd1
Added some code commentary and info in the README.
maratal Jul 12, 2023
caafd6d
Updated entitlements with common data.
maratal Jul 12, 2023
b47b9d6
Updated for Xcode 14.3
maratal Jul 13, 2023
dd82722
Renamed `shouldRequest...` method to include "Ably" in the name (like…
maratal Jul 15, 2023
9960e64
Added successful push details update callback.
maratal Jul 15, 2023
b2bffc4
Changed behaviour of the `shouldRequestOtherDeviceTokensForAblyPush` …
maratal Jul 15, 2023
3af42e9
Documentation updated
maratal Jul 15, 2023
17e1466
Revert "Updated for Xcode 14.3"
maratal Jul 16, 2023
cdc6b94
Removed `ARTPushRegistererDelegate.shouldRequestOtherDeviceTokensForA…
maratal Jul 16, 2023
7dc36cc
Use `didUpdateAblyPush:` instead of a delay to wait for the result of…
maratal Jul 16, 2023
bf97870
Revert "Made `deviceTokenString` a public utility method"
maratal Jul 16, 2023
9ec3d51
Example app extension for hex representtion for device token.
maratal Jul 16, 2023
6e65629
Updated comments for the new `ARTPushProtocol` methods.
maratal Jul 16, 2023
6fcd359
Removed Apple location push entitlements from the project.
maratal Jul 16, 2023
7e39225
Fixed app group entitlements
maratal Jul 16, 2023
59af068
Updated README on using entitlements.
maratal Jul 16, 2023
af0a5b4
Updated strings with common data.
maratal Jul 16, 2023
9432e48
Updated incorrect logger usage.
maratal Jul 16, 2023
0463c16
Removed optional and a comment to it.
maratal Jul 16, 2023
cfb088d
Added commentary on using `LocationPushEventsView` by users without X…
maratal Jul 16, 2023
f86b8d6
Revert "Removed Apple location push entitlements from the project."
maratal Jul 19, 2023
495c71d
Changed bundle-id strings for the Example app.
maratal Jul 19, 2023
794e634
Updated documentation.
maratal Jul 19, 2023
f9338a5
Updated tests for the new proposed spec RSH3e2c
maratal Jul 19, 2023
7c25324
Show activation alert in any case (even if token are not ready yet).
maratal Jul 19, 2023
53a1c15
Read legacy token in `ARTRest` too.
maratal Jul 19, 2023
50eb055
Those lines are the only that are changed when adding/remove app grou…
maratal Jul 20, 2023
14cd8d5
Added app target for use with location push extension.
maratal Jul 23, 2023
fd06242
Added variable app group identifier
maratal Jul 23, 2023
2656ad1
Changed bundle identifiers for better display in the AppGroups sectio…
maratal Jul 23, 2023
ec37262
Updated documentation.
maratal Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/AblyPush/AblyPushExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct ContentView: View {
NavigationLink {
LocationPushEventsView()
} label: {
Text("List of location push events")
Text("Location push events")
}
.padding()
Spacer()
Expand Down
18 changes: 16 additions & 2 deletions Examples/AblyPush/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
## Push Notifications Example

This app gives you a brief understanding of how Ably's Push Notifications work.
You will need a real iOS device to test this functionality.

- First, go to https://ably.com/accounts/, create an app and copy API key from API Keys tab of the app's dashboard.
- Go to the `Notifications` tab of the Ably's app dashboard and scroll to the `Push Notifications Setup` section. Press `Configure Push` and follow the instructions there.
- Insert it instead of an empty string in the `key` property's value inside the `AblyHelper` class.
- Make sure you've selected your development team in the `Signing & Capabilities` tab of the Xcode project target settings and all the provisioning profiles created without errors.
- Make sure you've selected your development team in the `Signing & Capabilities` tab of the Xcode project target settings and all the provisioning profiles created without errors (update the `bundle-id` for the `AblyPushExample` target as needed).
- Build and Run the app on your device.
- Hit "Activate" button, then hit "Print Token". You should see "IDENTITY TOKEN: exists" printed in the debug output window.
- Hit "Device Details" to display Ably push device registration info after successful activation.
- Go to the `Notifications` tab of the Ably's app dashboard again and scroll to the `Push Inspector` section. Fill in `Title` and `Body` fields of the push notification. Then insert "basic-apns-example" in the `Client ID` field and press enter. Then hit "Push to client" button. You should now see the notification on the screen of your device.
- Also you can send notifications from the app itself if you tick `Push Admin` capability in your API key settings in the app's dashboard. Just hit "Send Push" button to send a predefined push notification which is also will be displayed on your device's screen right away. You can change this behavior in the `UNUserNotificationCenterDelegate` extension for the `AblyHelper` by editing `completionHandler([.banner, .sound])` line of code.
- Also you can send notifications from the app itself if you tick `Push Admin` capability in your API key settings in the app's dashboard. Just hit "Send Push" button to send a predefined push notification which is also will be displayed on your device's screen right away. You can change this behavior in the `UNUserNotificationCenterDelegate` extension for the `AblyHelper` by editing `completionHandler([.banner, .sound])` line of code.

### Location pushes

* In order to use this capability (starting from iOS 15), you need to apply for the special entitlement on the Apple's developer portal. Follow instructions [here](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_location_push) on how to do that.

* Update the `bundle-id` for the `AblyPushExample` and `AblyLocationPush` targets as needed.
lawrence-forooghian marked this conversation as resolved.
Show resolved Hide resolved

* To receive location push notifications you need to request another device token specifically for the location pushes purpose. You do so by calling `CLLocationManager.startMonitoringLocationPushes(completion:)` within a `ARTPushRegistererDelegate.didActivateAblyPush(:)` delegate method (which is a callback for the `ARTRealtime.push.activate()` call).

* Once you receive the location push token, save it by calling a new `ARTPush.didRegisterForLocationNotifications(withDeviceToken:realtime:)` method (note the "Location" word in the name of this method). Ably will call the `ARTPushRegistererDelegate.didUpdateAblyPush:` callback on a successful or failed attempt to save the token.

* Use the "Location push events" button in the example app to open a list of received location pushed notifications.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,7 @@ func application(_ application: UIApplication, didFailToRegisterForRemoteNotific

Starting with iOS 15, Apple supports power efficient way to request location trough [location push service extension](https://developer.apple.com/documentation/corelocation/creating_a_location_push_service_extension).

To use this new functionality you should obtain Apple entitlments, create location push service extension and make some tweaks in your push notifications code within your app:

* Add Apple location pushes entitlments into your project ("AblyLocationPush" folder).

* In addition to saving your regular device token by calling `ARTPush.didRegisterForRemoteNotifications(withDeviceToken:realtime:)` you should request another device token specifically for the location pushes purpose. You do so by calling `CLLocationManager.startMonitoringLocationPushes(completion:)` within a `ARTPushRegistererDelegate.didActivateAblyPush(:)` delegate callback or whenever is appropriate in your app.

* Once you receive the location push token, save it by calling a new `ARTPush.didRegisterForLocationNotifications(withDeviceToken:realtime:)` method (note the "Location" word in the name of this method).

* To see received location push notifications in the UI you need to update both "AblyPushExample.entitlements" file and the file you received from Apple and add appropriate value under the `com.apple.security.application-groups` key ("group.{your_bundle_identifier}"). It is because application groups is the only way app and its location push extension can exchange information.

See [embed APNs example app](https://github.com/ably/ably-cocoa/tree/main/Examples/AblyPush) for more details on how this should be implemented.
Refer to the [embed APNs example app](https://github.com/ably/ably-cocoa/blob/main/Examples/AblyPush/README.md) on how this can be implemented.

Only one instance of `ARTRest` or `ARTRealtime` at a time must be [activated for receiving push notifications](https://www.ably.com/docs/general/push/activate-subscribe). Having more than one activated instance at a time may have unexpected consequences.

Expand Down