Skip to content

Commit

Permalink
Mainly localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
below committed Jul 29, 2022
1 parent b2866b4 commit cefc6f0
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 82 deletions.
35 changes: 35 additions & 0 deletions GeofenceTester.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
CB655F6F28534E2700EBCABA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CB655F6E28534E2700EBCABA /* Assets.xcassets */; };
CB655F7228534E2700EBCABA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CB655F7028534E2700EBCABA /* LaunchScreen.storyboard */; };
CB655F7E2856A43B00EBCABA /* RegionsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */; };
CB97AE3F286DC6410067B1BF /* RegionsListVC+CoreLocationsDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB97AE3E286DC6410067B1BF /* RegionsListVC+CoreLocationsDelegate.swift */; };
CBBF88CF286F269B00E4E1F0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = CBBF88CD286F269B00E4E1F0 /* InfoPlist.strings */; };
CBBF88D2286F269B00E4E1F0 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CBBF88D0286F269B00E4E1F0 /* Localizable.strings */; };
CBE711EF2868EE36008F51C4 /* RegionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711EE2868EE36008F51C4 /* RegionViewController.swift */; };
CBE711F1286915A8008F51C4 /* EventRecord.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711F0286915A8008F51C4 /* EventRecord.swift */; };
CBE711F3286920FD008F51C4 /* EventsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */; };
Expand All @@ -33,6 +36,11 @@
CB655F7128534E2700EBCABA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
CB655F7328534E2700EBCABA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionsListViewController.swift; sourceTree = "<group>"; };
CB97AE3D286DB2840067B1BF /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Main.strings; sourceTree = "<group>"; };
CB97AE3E286DC6410067B1BF /* RegionsListVC+CoreLocationsDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RegionsListVC+CoreLocationsDelegate.swift"; sourceTree = "<group>"; };
CBBF88CE286F269B00E4E1F0 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/InfoPlist.strings; sourceTree = "<group>"; };
CBBF88D1286F269B00E4E1F0 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Localizable.strings; sourceTree = "<group>"; };
CBBF88D3286F29ED00E4E1F0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
CBE711EE2868EE36008F51C4 /* RegionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionViewController.swift; sourceTree = "<group>"; };
CBE711F0286915A8008F51C4 /* EventRecord.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventRecord.swift; sourceTree = "<group>"; };
CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsTableViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,6 +84,7 @@
CBE71236286C7E7A008F51C4 /* Keys.swift */,
CB655F6728534E2600EBCABA /* SceneDelegate.swift */,
CB655F7D2856A43B00EBCABA /* RegionsListViewController.swift */,
CB97AE3E286DC6410067B1BF /* RegionsListVC+CoreLocationsDelegate.swift */,
CBE711EE2868EE36008F51C4 /* RegionViewController.swift */,
CBE711F2286920FD008F51C4 /* EventsTableViewController.swift */,
CBE711F0286915A8008F51C4 /* EventRecord.swift */,
Expand All @@ -84,6 +93,8 @@
CB655F6E28534E2700EBCABA /* Assets.xcassets */,
CB655F7028534E2700EBCABA /* LaunchScreen.storyboard */,
CB655F7328534E2700EBCABA /* Info.plist */,
CBBF88D0286F269B00E4E1F0 /* Localizable.strings */,
CBBF88CD286F269B00E4E1F0 /* InfoPlist.strings */,
);
path = GeofenceTester;
sourceTree = "<group>";
Expand Down Expand Up @@ -135,6 +146,7 @@
knownRegions = (
en,
Base,
de,
);
mainGroup = CB655F5928534E2600EBCABA;
packageReferences = (
Expand All @@ -154,7 +166,9 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CBBF88D2286F269B00E4E1F0 /* Localizable.strings in Resources */,
CB655F7228534E2700EBCABA /* LaunchScreen.storyboard in Resources */,
CBBF88CF286F269B00E4E1F0 /* InfoPlist.strings in Resources */,
CB655F6F28534E2700EBCABA /* Assets.xcassets in Resources */,
CB655F6D28534E2600EBCABA /* Main.storyboard in Resources */,
);
Expand All @@ -167,6 +181,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CB97AE3F286DC6410067B1BF /* RegionsListVC+CoreLocationsDelegate.swift in Sources */,
CBE711F1286915A8008F51C4 /* EventRecord.swift in Sources */,
CBE71237286C7E7A008F51C4 /* Keys.swift in Sources */,
CB655F6628534E2600EBCABA /* AppDelegate.swift in Sources */,
Expand All @@ -185,6 +200,7 @@
isa = PBXVariantGroup;
children = (
CB655F6C28534E2600EBCABA /* Base */,
CB97AE3D286DB2840067B1BF /* de */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand All @@ -197,13 +213,31 @@
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
CBBF88CD286F269B00E4E1F0 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
CBBF88CE286F269B00E4E1F0 /* de */,
CBBF88D3286F29ED00E4E1F0 /* en */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
CBBF88D0286F269B00E4E1F0 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
CBBF88D1286F269B00E4E1F0 /* de */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
CB655F7428534E2700EBCABA /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
Expand Down Expand Up @@ -264,6 +298,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
Expand Down
1 change: 1 addition & 0 deletions GeofenceTester/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keys.swift
1 change: 1 addition & 0 deletions GeofenceTester/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
</barButtonItem>
</navigationItem>
<connections>
<outlet property="addButton" destination="BJ6-F4-XfY" id="UTb-4K-1NO"/>
<outlet property="mapView" destination="PTq-kR-Xju" id="Xpb-Pa-2kJ"/>
<segue destination="abz-U4-dF9" kind="showDetail" identifier="RegionDetail" id="r59-b2-f5b"/>
</connections>
Expand Down
77 changes: 77 additions & 0 deletions GeofenceTester/RegionsListVC+CoreLocationsDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// RegionsListVC+CoreLocationsDelegate.swift
// GeofenceTester
//
// Created by Alexander von Below on 30.06.22.
//

import UIKit
import CoreLocation

extension RegionsListViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
process(event: .ENTER, region: region)
}

func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
process(event: .EXIT, region: region)
}

private func process (event: EventRecord.EventType, region: CLRegion) {
let content = UNMutableNotificationContent()
let title: String
switch event {
case .ENTER:
title = NSLocalizedString("Region Entered",
comment: "Push Notificaton Title")
case .EXIT:
title = NSLocalizedString("Region Exited",
comment: "Push Notificaton Title")
}
content.title = title
content.body = "\(region.identifier) \(Date())"

let eventRecord = EventRecord(event: event,
identifier: region.identifier,
date: Date())
do {
try storage.store(eventRecord)
}
catch let error {
self.handleError(error)
}
let request = UNNotificationRequest(identifier: region.identifier,
content: content,
trigger: nil)
UNUserNotificationCenter.current().add(request)
}

func locationManager( _ manager: CLLocationManager,
monitoringDidFailFor region: CLRegion?,
withError error: Error
) {
self.handleError(error)
}

func locationManager(_ manager: CLLocationManager,
didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted, .denied:
// Disable your app's location features
self.handleError("Warning: Location restricted or denied")

case .authorizedWhenInUse:
// Enable your app's location features.
self.handleError("Warning: Location InUse Only")

case .authorizedAlways:
self.mapView.showsUserLocation = true
// Enable or prepare your app's location features that can run any time.

case .notDetermined:
self.handleError("Warning: Location Not Determined")
default:
self.handleError("Warning: Switch fell through")
}
}
}
101 changes: 19 additions & 82 deletions GeofenceTester/RegionsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class RegionsListViewController: UIViewController {
private var logger = Logger()

@IBOutlet var mapView: MKMapView!
@IBOutlet var addButton: UIBarButtonItem!

override func viewDidLoad() {
super.viewDidLoad()

addButton.accessibilityLabel = NSLocalizedString("Add Monitored Region at current location", comment: "Accessibilty label for add button")
locationManager.delegate = self

registerMapAnnotationViews()
Expand All @@ -31,7 +33,11 @@ class RegionsListViewController: UIViewController {
self.mapView.showsUserLocation = true
mapView.setCenter(mapView.userLocation.coordinate, animated: true)
default:
let alert = UIAlertController(title: "No authorization", message: "This app requires the location services to be authorised", preferredStyle: .alert)
let alert = UIAlertController(title: NSLocalizedString("No authorization",
comment: "Alert: Authorization to Localization denied"),
message: NSLocalizedString("This app requires the location services to be authorised",
comment: "Alert: Authorization to Localization denied"),
preferredStyle: .alert)
self.present(alert, animated: true)
}
}
Expand All @@ -47,14 +53,20 @@ class RegionsListViewController: UIViewController {
}

@IBAction func addRegionAction() {
let alertController = UIAlertController(title: "New Region", message: "Please enter a name", preferredStyle: .alert)
let alertController = UIAlertController(title: NSLocalizedString("New Region",
comment: "New Region Alert"),
message: NSLocalizedString("Please enter a name",
comment: "New Region Alert"),
preferredStyle: .alert)
alertController.addTextField()
alertController.addAction(UIAlertAction(title: "Cancel",
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel",
comment: "New Region Alert"),
style: .cancel,
handler: { _ in
return
}))
alertController.addAction(UIAlertAction(title: "OK",
alertController.addAction(UIAlertAction(title: NSLocalizedString("OK",
comment: "New Region Alert"),
style: .default,
handler: { _ in
guard let identifier = alertController.textFields?.first?.text else {
Expand Down Expand Up @@ -121,11 +133,11 @@ class RegionsListViewController: UIViewController {
mapView.showAnnotations(mapAnnotations, animated: true)
}

private func handleError (_ error: Error) {
internal func handleError (_ error: Error) {
handleError(error.localizedDescription)
}

private func handleError (_ error: String) {
internal func handleError (_ error: String) {
logger.error("\(error)")
}

Expand All @@ -136,8 +148,7 @@ class RegionsListViewController: UIViewController {

if let destination = segue.destination as? RegionViewController {
guard let annotation = sender as? MKAnnotation else {
let logger = Logger()
logger.log(level: .error, "Sender was not MKAnnotation")
self.handleError("Sender was not MKAnnotation")
return
}
guard let identifier = annotation.title else {
Expand Down Expand Up @@ -186,77 +197,3 @@ extension RegionsListViewController: MKMapViewDelegate {
self.performSegue(withIdentifier: "RegionDetail", sender: view.annotation)
}
}

// MARK: - CLLocationManagerDelegate

extension RegionsListViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
let date = Date()
let content = UNMutableNotificationContent()
content.title = "Region Entered"
content.body = "\(region.identifier) \(date)"

let eventRecord = EventRecord(event: .ENTER,
identifier: region.identifier,
date: date)
do {
try storage.store(eventRecord)
}
catch let error {
self.handleError(error)
}
let request = UNNotificationRequest(identifier: region.identifier,
content: content,
trigger: nil)
UNUserNotificationCenter.current().add(request)
}

func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
let content = UNMutableNotificationContent()
content.title = "Region Exited"
content.body = "\(region.identifier) \(Date())"

let eventRecord = EventRecord(event: .EXIT,
identifier: region.identifier,
date: Date())
do {
try storage.store(eventRecord)
}
catch let error {
self.handleError(error)
}
let request = UNNotificationRequest(identifier: region.identifier,
content: content,
trigger: nil)
UNUserNotificationCenter.current().add(request)
}

func locationManager( _ manager: CLLocationManager,
monitoringDidFailFor region: CLRegion?,
withError error: Error
) {
self.handleError(error)
}

func locationManager(_ manager: CLLocationManager,
didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted, .denied:
// Disable your app's location features
self.handleError("Warning: Location restricted or denied")

case .authorizedWhenInUse:
// Enable your app's location features.
self.handleError("Warning: Location InUse Only")

case .authorizedAlways:
self.mapView.showsUserLocation = true
// Enable or prepare your app's location features that can run any time.

case .notDetermined:
self.handleError("Warning: Location Not Determined")
default:
self.handleError("Warning: Switch fell through")
}
}
}
4 changes: 4 additions & 0 deletions GeofenceTester/de.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Privacy - Location Always and When In Use Usage Description */
"NSLocationWhenInUseUsageDescription" = "Der Zweck dieser App ist Region Monitoring. Dazu benötigt sie Ortungsdienste im Hintergrund";
"NSLocationAlwaysAndWhenInUseUsageDescription" = "Der Zweck dieser App ist Region Monitoring. Dazu benötigt sie Ortungsdienste im Hintergrund";

27 changes: 27 additions & 0 deletions GeofenceTester/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Accessibilty label for add button */
"Add Monitored Region at current location" = "Füge eine überwachte Region am aktuellen Ort hinzu";

/* New Region Alert */
"Cancel" = "Abbrechen";

/* New Region Alert */
"New Region" = "Neue Region";

/* Alert: Authorization to Localization denied */
"No authorization" = "Keine Authorization";

/* New Region Alert */
"OK" = "OK";

/* New Region Alert */
"Please enter a name" = "Name für die Region";

/* Push Notificaton Title */
"Region Entered" = "Region betreten";

/* Push Notificaton Title */
"Region Exited" = "Region verlassen";

/* Alert: Authorization to Localization denied */
"This app requires the location services to be authorised" = "Die Ortungsdienste müssen für diese App zugelassen sein";

9 changes: 9 additions & 0 deletions GeofenceTester/de.lproj/Main.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Class = "UIButton"; configuration.title = "Delete"; ObjectID = "pRa-cH-jsG"; */
"pRa-cH-jsG.configuration.title" = "Löschen";

/* Class = "UIButton"; normalTitle = "Button"; ObjectID = "pRa-cH-jsG"; */
"pRa-cH-jsG.normalTitle" = "Button";

/* Class = "UILabel"; text = "Label"; ObjectID = "YxR-jO-lcY"; */
"YxR-jO-lcY.text" = "Label";

3 changes: 3 additions & 0 deletions GeofenceTester/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Privacy - Location When In Use Usage Description */
"NSLocationWhenInUseUsageDescription" = "This is a region monitoring testing app. It needs background location updates";
"NSLocationAlwaysAndWhenInUseUsageDescription" = "This is a region monitoring testing app. It needs background location updates";

0 comments on commit cefc6f0

Please sign in to comment.