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 all commits
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
10 changes: 10 additions & 0 deletions Examples/AblyPush/AblyLocationPush/AblyLocationPush.entitlements
lawrence-forooghian marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.$(CFBundleIdentifier)</string>
</array>
</dict>
</plist>
13 changes: 13 additions & 0 deletions Examples/AblyPush/AblyLocationPush/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.location.push.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).LocationPushService</string>
</dict>
</dict>
</plist>
83 changes: 83 additions & 0 deletions Examples/AblyPush/AblyLocationPush/LocationPushService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import CoreLocation

struct LocationPushEvent: Codable {
var id: UUID
var receivedAt: Date
var jsonPayload: Data
}

class LocationPushService: NSObject, CLLocationPushServiceExtension, CLLocationManagerDelegate {

var completion: (() -> Void)?
var locationManager: CLLocationManager!

func didReceiveLocationPushPayload(_ payload: [String : Any], completion: @escaping () -> Void) {
recordPushPayload(payload)

self.completion = completion
self.locationManager = CLLocationManager()
self.locationManager.delegate = self
self.locationManager.requestLocation()
}

/**
* This method is used to exchange information between the app and the extension.
* This gives a user, who testing location pushes without access to the debug console, to see actual notifications in the `LocationPushEventsView`.
*/
private func recordPushPayload(_ payload: [String : Any]) {
lawrence-forooghian marked this conversation as resolved.
Show resolved Hide resolved
guard let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.\(Bundle.main.bundleIdentifier!)") else {
return print("App Groups were not configured properly. Check 'Signing & Capabilities' tab of the project settings.")
}

let dataFileURL = sharedContainerURL.appendingPathComponent("dataFile")

let readCoordinator = NSFileCoordinator()
var readError: NSError? = nil
var data: Data? = nil
readCoordinator.coordinate(readingItemAt: dataFileURL, error: &readError) { url in
if FileManager.default.fileExists(atPath: url.path) {
data = FileManager.default.contents(atPath: url.path)!
}
}

guard readError == nil else {
return
}

let event = LocationPushEvent(id: UUID(), receivedAt: Date(), jsonPayload: try! JSONSerialization.data(withJSONObject: payload))
var events: [LocationPushEvent] = []

if let data {
events = try! JSONDecoder().decode([LocationPushEvent].self, from: data)
events.append(event)
} else {
events = [event]
}

let newData = try! JSONEncoder().encode(events)

let writeCoordinator = NSFileCoordinator()
var writeError: NSError? = nil
writeCoordinator.coordinate(writingItemAt: dataFileURL, error: &writeError) { url in
try! newData.write(to: url)
}
}

func serviceExtensionWillTerminate() {
// Called just before the extension will be terminated by the system.
self.completion?()
}

// MARK: - CLLocationManagerDelegate methods

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// Process the location(s) as needed
print("Locations received: \(locations)")
self.completion?()
}

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Location manager failed: \(error)")
self.completion?()
}
}
Loading