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

Fix Email and Text Message Issues & Support iOS 17 #8

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix Email and Text Message issues and support iOS 17
  • Loading branch information
PSchmiedmayer committed Jun 23, 2023
commit 48a2d883845f7cc94c5b3047c220d69cbfcb1247
12 changes: 9 additions & 3 deletions Sources/SpeziContact/Contact Views/ContactCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ struct ContactCard: View {
ContactView(contact: contact)
.padding()
.background {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(.systemBackground))
.shadow(radius: 5)
if #available(iOS 17.0, *) {
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(.background)
.shadow(radius: 5)
} else {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(.systemBackground))
.shadow(radius: 5)
}
}
}

Expand Down
20 changes: 15 additions & 5 deletions Sources/SpeziContact/Contact Views/ContactView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct ContactView: View {


private var contactOptions: (grid: some RandomAccessCollection<ContactOption>, leftOverStack: some RandomAccessCollection<ContactOption>) {
let columnCount = Int(contactGridWidth / contentElementWidth)
let columnCount = max(Int(contactGridWidth / max(contentElementWidth, 64)), 1)
let (numberOfRows, leftOverElements) = contact.contactOptions.count.quotientAndRemainder(dividingBy: columnCount)
return (contact.contactOptions.dropLast(leftOverElements), contact.contactOptions.dropFirst(columnCount * numberOfRows))
}
Expand Down Expand Up @@ -105,8 +105,13 @@ public struct ContactView: View {
if let address = contact.address {
Button(action: openMaps) {
ZStack {
RoundedRectangle(cornerRadius: 10.0)
.foregroundColor(Color(.systemGroupedBackground))
if #available(iOS 17.0, *) {
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(.background.secondary)
} else {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(.systemGroupedBackground))
}
HStack(alignment: .top) {
VStack(alignment: .leading, spacing: 4) {
Text("CONTACT_ADDRESS", bundle: .module)
Expand Down Expand Up @@ -140,8 +145,13 @@ public struct ContactView: View {
private func contactButton(_ contactOption: ContactOption) -> some View {
Button(action: contactOption.action) {
ZStack {
RoundedRectangle(cornerRadius: 10.0)
.foregroundColor(Color(.systemGroupedBackground))
if #available(iOS 17.0, *) {
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(.background.secondary)
} else {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(.systemGroupedBackground))
}
VStack(spacing: 8) {
contactOption.image
.font(.title3)
Expand Down
23 changes: 7 additions & 16 deletions Sources/SpeziContact/Models/ContactOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public struct ContactOption {
}

extension ContactOption {
private static var delegateReference: NSObject?

private static var rootViewController: UIViewController? {
UIApplication
.shared
Expand Down Expand Up @@ -69,19 +71,14 @@ extension ContactOption {
image: Image(systemName: "message.fill"),
title: String(localized: "CONTACT_OPTION_TEXT", bundle: .module)
) {
guard MFMessageComposeViewController.canSendText() else {
guard let url = URL(string: "sms:\(number)"), UIApplication.shared.canOpenURL(url) else {
presentAlert(
title: String(localized: "CONTACT_OPTION_TEXT", bundle: .module),
message: String(localized: "CONTACT_OPTION_TEXT_MANUAL \(number)", bundle: .module)
)
return
}

let controller = MFMessageComposeViewController()

controller.recipients = [number]

rootViewController?.present(controller, animated: true, completion: nil)
UIApplication.shared.open(url)
}
}

Expand All @@ -95,21 +92,15 @@ extension ContactOption {
image: Image(systemName: "envelope.fill"),
title: String(localized: "CONTACT_OPTION_EMAIL", bundle: .module)
) {
guard MFMailComposeViewController.canSendMail() else {
guard let subject = (subject ?? "").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: "mailto:\(addresses.joined(separator: ";"))?subject=\(subject)"), UIApplication.shared.canOpenURL(url) else {
presentAlert(
title: String(localized: "CONTACT_OPTION_EMAIL", bundle: .module),
message: String(localized: "CONTACT_OPTION_EMAIL_MANUAL \(addresses.joined(separator: ", "))", bundle: .module)
)
return
}

let controller = MFMailComposeViewController()
controller.setToRecipients(addresses)
if let subject {
controller.setSubject(subject)
}

rootViewController?.present(controller, animated: true, completion: nil)
UIApplication.shared.open(url)
}
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/UITests/TestApp.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
}
],
"defaultOptions" : {
"codeCoverage" : {
"targets" : [
{
"containerPath" : "container:..\/..",
"identifier" : "SpeziContact",
"name" : "SpeziContact"
}
]
},
"targetForVariableExpansion" : {
"containerPath" : "container:UITests.xcodeproj",
"identifier" : "2F6D139128F5F384007C25D6",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SpeziContact"
BuildableName = "SpeziContact"
BlueprintName = "SpeziContact"
ReferencedContainer = "container:../..">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F6D139128F5F384007C25D6"
BuildableName = "TestApp.app"
BlueprintName = "TestApp"
ReferencedContainer = "container:UITests.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F6D13AB28F5F386007C25D6"
BuildableName = "TestAppUITests.xctest"
BlueprintName = "TestAppUITests"
ReferencedContainer = "container:UITests.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F6D139128F5F384007C25D6"
BuildableName = "TestApp.app"
BlueprintName = "TestApp"
ReferencedContainer = "container:UITests.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2F6D139128F5F384007C25D6"
BuildableName = "TestApp.app"
BlueprintName = "TestApp"
ReferencedContainer = "container:UITests.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>