-
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.
A preview of an implementation of the location pushes.
- Loading branch information
Showing
15 changed files
with
568 additions
and
46 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
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> |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
import CoreLocation | ||
|
||
class LocationPushService: NSObject, CLLocationPushServiceExtension, CLLocationManagerDelegate { | ||
|
||
var completion: (() -> Void)? | ||
var locationManager: CLLocationManager! | ||
|
||
func didReceiveLocationPushPayload(_ payload: [String : Any], completion: @escaping () -> Void) { | ||
self.completion = completion | ||
self.locationManager = CLLocationManager() | ||
self.locationManager.delegate = self | ||
self.locationManager.requestLocation() | ||
} | ||
|
||
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?() | ||
} | ||
} |
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
Oops, something went wrong.