-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into feature/no-connection…
…-serial # Conflicts: # Source/ARTRealtimeChannel.m # Test/Tests/ARTDefaultTests.swift
- Loading branch information
Showing
53 changed files
with
1,929 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Examples/AblyPush/AblyLocationPush/AblyLocationPush.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
83
Examples/AblyPush/AblyLocationPush/LocationPushService.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) { | ||
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?() | ||
} | ||
} |
Oops, something went wrong.