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

Integrate Siri shortcuts to enable/disable gps tracking #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
97 changes: 97 additions & 0 deletions Intents.intentdefinition
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>1AigIl</string>
<key>INIntentDefinitionSystemVersion</key>
<string>23F79</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>15F31d</string>
<key>INIntentDefinitionToolsVersion</key>
<string>15.4</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>generic</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>starts tracking with gps</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a correct description. It doesn't necessarily use GPS. Also need proper letter cases

<key>INIntentDescriptionID</key>
<string>8atNz2</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>StartTrackingService</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file I only see the start track intent. Where is the stop defined?

<key>INIntentParameterCombinations</key>
<dict>
<key></key>
<dict>
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
</dict>
</dict>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>yes</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>ZxxgPH</string>
<key>INIntentResponseCodeFormatString</key>
<string>yay</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>5l9bCc</string>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeConciseFormatString</key>
<string>no</string>
<key>INIntentResponseCodeConciseFormatStringID</key>
<string>fwaOIl</string>
<key>INIntentResponseCodeFormatString</key>
<string>nay</string>
<key>INIntentResponseCodeFormatStringID</key>
<string>ziguoJ</string>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Start Tracking Service</string>
<key>INIntentTitleID</key>
<string>kVcJ5o</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Do</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>
21 changes: 21 additions & 0 deletions TraccarClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
58FB0E542C35E708001D55B6 /* StartTrackingIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FB0E532C35E708001D55B6 /* StartTrackingIntent.swift */; };
58FB0E562C35E90A001D55B6 /* StopTrackingIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FB0E552C35E90A001D55B6 /* StopTrackingIntent.swift */; };
5E394EBE28A9CC7600396F33 /* BatteryStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E394EBD28A9CC7600396F33 /* BatteryStatus.swift */; };
5E716A271F63A0B100A2DBC3 /* DistanceCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E716A261F63A0B100A2DBC3 /* DistanceCalculator.swift */; };
5E716A291F63A45A00A2DBC3 /* RequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E716A281F63A45A00A2DBC3 /* RequestManager.swift */; };
Expand Down Expand Up @@ -65,6 +67,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
58FB0E4F2C35DF7F001D55B6 /* TraccarClient.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TraccarClient.entitlements; sourceTree = "<group>"; };
58FB0E532C35E708001D55B6 /* StartTrackingIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartTrackingIntent.swift; sourceTree = "<group>"; };
58FB0E552C35E90A001D55B6 /* StopTrackingIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StopTrackingIntent.swift; sourceTree = "<group>"; };
5E394EBD28A9CC7600396F33 /* BatteryStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryStatus.swift; sourceTree = "<group>"; };
5E716A261F63A0B100A2DBC3 /* DistanceCalculator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DistanceCalculator.swift; sourceTree = "<group>"; };
5E716A281F63A45A00A2DBC3 /* RequestManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RequestManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,6 +159,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
58FB0E522C35E6DE001D55B6 /* Intents */ = {
isa = PBXGroup;
children = (
58FB0E532C35E708001D55B6 /* StartTrackingIntent.swift */,
58FB0E552C35E90A001D55B6 /* StopTrackingIntent.swift */,
);
name = Intents;
sourceTree = "<group>";
};
CED4870F17DB1BF6007FCF57 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -190,6 +204,8 @@
CED4872117DB1BF6007FCF57 /* TraccarClient */ = {
isa = PBXGroup;
children = (
58FB0E522C35E6DE001D55B6 /* Intents */,
58FB0E4F2C35DF7F001D55B6 /* TraccarClient.entitlements */,
CE5899C71B115C9100ED70D2 /* Images.xcassets */,
CED4873317DB1BF6007FCF57 /* MainStoryboard.storyboard */,
CEF643241B919FFA00195CEA /* LaunchScreen.xib */,
Expand Down Expand Up @@ -389,10 +405,12 @@
files = (
CB7ED0801F6602CD00A33FCF /* Position.swift in Sources */,
CBAA0F7F1F68E807008BBBBE /* MainViewController.swift in Sources */,
58FB0E562C35E90A001D55B6 /* StopTrackingIntent.swift in Sources */,
CB7ED0821F661B4F00A33FCF /* PositionProvider.swift in Sources */,
CB4197991F67724F008F301C /* NetworkManager.swift in Sources */,
CB7ED0841F662BAF00A33FCF /* AppDelegate.swift in Sources */,
5E394EBE28A9CC7600396F33 /* BatteryStatus.swift in Sources */,
58FB0E542C35E708001D55B6 /* StartTrackingIntent.swift in Sources */,
5E716A2B1F63A60800A2DBC3 /* ProtocolFormatter.swift in Sources */,
CBCE82F21B8D265800A7318B /* TraccarClient.xcdatamodeld in Sources */,
CBAA0F7D1F68E14C008BBBBE /* StatusViewController.swift in Sources */,
Expand Down Expand Up @@ -522,6 +540,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = TraccarClient/TraccarClient.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -692,6 +711,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = TraccarClient/TraccarClient.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 59;
Expand Down Expand Up @@ -723,6 +743,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = TraccarClient/TraccarClient.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
Expand Down
1 change: 1 addition & 0 deletions TraccarClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import UIKit
import CoreData
import Firebase
import IntentsUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PositionProviderDelegate {
Expand Down
20 changes: 20 additions & 0 deletions TraccarClient/StartTrackingIntent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import AppIntents
import SwiftUI

@available(iOS 16, *)
struct StartTrackingIntent: AppIntent {

static let title: LocalizedStringResource = "Start Tracking Service"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this


func perform() async throws -> some IntentResult & ProvidesDialog {
var trackingController: TrackingController?
let userDefaults = UserDefaults.standard
if !userDefaults.bool(forKey: "service_status_preference") {
userDefaults.setValue(true, forKey: "service_status_preference")
await StatusViewController.addMessage(NSLocalizedString("Tracking Service created", comment: ""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reuse existing string

trackingController = TrackingController()
trackingController?.start()
}
return .result(dialog: "Tracking Service Started")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be localized as well. And probably reuse string as well.

}
}
20 changes: 20 additions & 0 deletions TraccarClient/StopTrackingIntent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import AppIntents
import SwiftUI

@available(iOS 16, *)
struct StopTrackingIntent: AppIntent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for strings here.


static let title: LocalizedStringResource = "Stop Tracking Service"

func perform() async throws -> some IntentResult & ProvidesDialog {
var trackingController: TrackingController?
let userDefaults = UserDefaults.standard
if userDefaults.bool(forKey: "service_status_preference") {
userDefaults.setValue(false, forKey: "service_status_preference")
await StatusViewController.addMessage(NSLocalizedString("Tracking Service destroyed", comment: ""))
trackingController?.stop()
trackingController = nil
}
return .result(dialog: "Tracking Service Stopped")
}
}
8 changes: 8 additions & 0 deletions TraccarClient/TraccarClient.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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.developer.siri</key>
<true/>
</dict>
</plist>