Skip to content

Commit 37ab615

Browse files
committed
Added feature to include user's full name
Fetched user's full name from the native contacts app and added functionality to include user's name when sending text emergency messages.
1 parent f408faa commit 37ab615

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

iosApp/VC.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@
426426
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
427427
GCC_WARN_UNUSED_FUNCTION = YES;
428428
GCC_WARN_UNUSED_VARIABLE = YES;
429+
INFOPLIST_KEY_NSContactsUsageDescription = "";
429430
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
430431
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
431432
MTL_FAST_MATH = YES;
@@ -481,6 +482,7 @@
481482
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
482483
GCC_WARN_UNUSED_FUNCTION = YES;
483484
GCC_WARN_UNUSED_VARIABLE = YES;
485+
INFOPLIST_KEY_NSContactsUsageDescription = "";
484486
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
485487
MTL_ENABLE_DEBUG_INFO = NO;
486488
MTL_FAST_MATH = YES;
@@ -500,17 +502,18 @@
500502
CODE_SIGN_IDENTITY = "Apple Development";
501503
CODE_SIGN_STYLE = Automatic;
502504
CURRENT_PROJECT_VERSION = 1;
503-
DEVELOPMENT_TEAM = 3334VHMS7U;
505+
DEVELOPMENT_TEAM = 5779RYBW52;
504506
GENERATE_INFOPLIST_FILE = YES;
505507
INFOPLIST_FILE = VC/Info.plist;
506508
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "This app uses Bluetooth to connect to a peripheral device.";
509+
INFOPLIST_KEY_NSContactsUsageDescription = "This app uses contacts to retrieve user's contact information";
507510
INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "This app uses location to notify contacts with current location";
508511
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "This app uses location to notify contacts with current location";
509512
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
510513
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
511514
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
512515
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
513-
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
516+
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
514517
LD_RUNPATH_SEARCH_PATHS = (
515518
"$(inherited)",
516519
"@executable_path/Frameworks",
@@ -536,17 +539,18 @@
536539
CODE_SIGN_IDENTITY = "Apple Development";
537540
CODE_SIGN_STYLE = Automatic;
538541
CURRENT_PROJECT_VERSION = 1;
539-
DEVELOPMENT_TEAM = 3334VHMS7U;
542+
DEVELOPMENT_TEAM = 5779RYBW52;
540543
GENERATE_INFOPLIST_FILE = YES;
541544
INFOPLIST_FILE = VC/Info.plist;
542545
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "This app uses Bluetooth to connect to a peripheral device.";
546+
INFOPLIST_KEY_NSContactsUsageDescription = "This app uses contacts to retrieve user's contact information";
543547
INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "This app uses location to notify contacts with current location";
544548
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "This app uses location to notify contacts with current location";
545549
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
546550
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
547551
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
548552
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
549-
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
553+
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
550554
LD_RUNPATH_SEARCH_PATHS = (
551555
"$(inherited)",
552556
"@executable_path/Frameworks",

iosApp/VC/Controllers/VCContactsViewController.swift

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,46 @@ class VCContactsViewController: UIViewController, UITableViewDataSource, CNConta
296296
}
297297
}
298298

299+
300+
/**
301+
Get's the user's Full Name from the contacts
302+
303+
- Parameters:
304+
- Returns: The full name of the user
305+
*/
306+
func getUsersFullName() -> String? {
307+
let semaphore = DispatchSemaphore(value: 0)
308+
var fullName: String?
309+
DispatchQueue.global(qos: .userInitiated).async {
310+
let store = CNContactStore()
311+
store.requestAccess(for: .contacts) { granted, error in
312+
if granted {
313+
let keys = [CNContactGivenNameKey, CNContactFamilyNameKey]
314+
let request = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
315+
var contacts = [CNContact]()
316+
do {
317+
try store.enumerateContacts(with: request) { contact, stop in
318+
if contact.isKeyAvailable(CNContactGivenNameKey) && contact.isKeyAvailable(CNContactFamilyNameKey) {
319+
contacts.append(contact)
320+
stop.pointee = true
321+
}
322+
}
323+
if let userContact = contacts.first {
324+
fullName = userContact.givenName + " " + userContact.familyName
325+
}
326+
} catch {
327+
print("Error fetching user's contact card: \(error.localizedDescription)")
328+
}
329+
} else {
330+
print("Access to contacts was not granted")
331+
}
332+
semaphore.signal()
333+
}
334+
}
335+
semaphore.wait()
336+
return fullName
337+
}
338+
299339
func textMessageWithTwilio() {
300340
// Get the location and stop
301341
let locationManager = CLLocationManager()
@@ -319,7 +359,13 @@ class VCContactsViewController: UIViewController, UITableViewDataSource, CNConta
319359
print("Geocoding error: \(error.localizedDescription)")
320360
return
321361
}
322-
var message = "I'm in an Emergency, here is my location: "
362+
363+
var namePlaceHolder = "VC app user"
364+
if let fullName = self.getUsersFullName() {
365+
namePlaceHolder = fullName
366+
}
367+
var message = "Hi, this is \(namePlaceHolder). I'm in an Emergency, here is my location:"
368+
323369
if let address = address {
324370
// Concatenate the address to the message
325371
message += address

iosApp/VC/Model.xcdatamodeld/Model.xcdatamodel/contents

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
<attribute name="contactId" optional="YES" attributeType="String"/>
55
<attribute name="contactName" optional="YES" attributeType="String"/>
66
<attribute name="contactPhoneNumber" optional="YES" attributeType="String"/>
7-
<attribute name="contactSource" optional="YES" attributeType="Transformable" valueTransformerName="NSKeyedUnarchiveFromDataTransformerName" customClassName="CNContact"/>
7+
<attribute name="contactSource" optional="YES" attributeType="Transformable" valueTransformerName="" customClassName="CNContact"/>
88
</entity>
99
</model>

0 commit comments

Comments
 (0)