Refactor QRCodeStyleView to streamline photo library permission handling. Remove deprecated permission check and implement a new method for custom logo selection that requests permissions dynamically. Enhance user experience by guiding users to settings if access is denied.

main
v504 2 months ago
parent c350669bba
commit a1bd7e8420

@ -114,36 +114,6 @@
endingLineNumber = "233"
landmarkName = "createInputComponent(for:emailConfig:wifiConfig:contactConfig:locationConfig:calendarConfig:socialConfig:phoneConfig:urlConfig:textConfig:)"
landmarkType = "7">
<Locations>
<Location
uuid = "937652B7-5A6D-4691-903E-F45D0841A211 - 4e0ffa10f92b8035"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "static MyQrCode.InputComponentFactory.createInputComponent(for: MyQrCode.QRCodeType, emailConfig: Swift.Optional&lt;MyQrCode.EmailInputConfig&gt;, wifiConfig: Swift.Optional&lt;MyQrCode.WiFiInputConfig&gt;, contactConfig: Swift.Optional&lt;MyQrCode.ContactInputConfig&gt;, locationConfig: Swift.Optional&lt;MyQrCode.LocationInputConfig&gt;, calendarConfig: Swift.Optional&lt;MyQrCode.CalendarInputConfig&gt;, socialConfig: Swift.Optional&lt;MyQrCode.SocialInputConfig&gt;, phoneConfig: Swift.Optional&lt;MyQrCode.PhoneInputConfig&gt;, urlConfig: Swift.Optional&lt;MyQrCode.URLInputConfig&gt;, textConfig: Swift.Optional&lt;MyQrCode.TextInputConfig&gt;) -&gt; SwiftUI.AnyView"
moduleName = "MyQrCode.debug.dylib"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/yc/xcodeProjects/MyQrCode/MyQrCode/Views/Components/InputComponentFactory.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "233"
endingLineNumber = "233">
</Location>
<Location
uuid = "937652B7-5A6D-4691-903E-F45D0841A211 - 4e0ffa10f92b8035"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "static MyQrCode.InputComponentFactory.createInputComponent(for: MyQrCode.QRCodeType, emailConfig: Swift.Optional&lt;MyQrCode.EmailInputConfig&gt;, wifiConfig: Swift.Optional&lt;MyQrCode.WiFiInputConfig&gt;, contactConfig: Swift.Optional&lt;MyQrCode.ContactInputConfig&gt;, locationConfig: Swift.Optional&lt;MyQrCode.LocationInputConfig&gt;, calendarConfig: Swift.Optional&lt;MyQrCode.CalendarInputConfig&gt;, socialConfig: Swift.Optional&lt;MyQrCode.SocialInputConfig&gt;, phoneConfig: Swift.Optional&lt;MyQrCode.PhoneInputConfig&gt;, urlConfig: Swift.Optional&lt;MyQrCode.URLInputConfig&gt;, textConfig: Swift.Optional&lt;MyQrCode.TextInputConfig&gt;) -&gt; SwiftUI.AnyView"
moduleName = "MyQrCode.debug.dylib"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/yc/xcodeProjects/MyQrCode/MyQrCode/Views/Components/InputComponentFactory.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "233"
endingLineNumber = "233">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -224,36 +194,6 @@
endingLineNumber = "281"
landmarkName = "calendarInfoDetailView(parsedData:)"
landmarkType = "7">
<Locations>
<Location
uuid = "0E8D1C5E-D350-449F-8C7B-5D789F9A72B1 - 437388a8c06debe1"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 () -&gt; Swift.Optional&lt;&lt;&lt;opaque return type of SwiftUI.View.frame(minWidth: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, idealWidth: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, maxWidth: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, minHeight: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, idealHeight: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, maxHeight: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, alignment: SwiftUI.Alignment) -&gt; some&gt;&gt;.0&gt; in closure #1 () -&gt; SwiftUI._ConditionalContent&lt;SwiftUI.TupleView&lt;(Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;)&gt;, &lt;&lt;opaque return type of SwiftUI.View.cornerRadius(_: CoreGraphics.CGFloat, antialiased: Swift.Bool) -&gt; some&gt;&gt;.0&gt; in MyQrCode.QRCodeDetailView.calendarInfoDetailView(parsedData: MyQrCode.ParsedQRData) -&gt; some"
moduleName = "MyQrCode.debug.dylib"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/yc/xcodeProjects/MyQrCode/MyQrCode/Views/History/QRCodeDetailView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "281"
endingLineNumber = "281">
</Location>
<Location
uuid = "0E8D1C5E-D350-449F-8C7B-5D789F9A72B1 - 437388a8c06debe1"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 () -&gt; Swift.Optional&lt;&lt;&lt;opaque return type of SwiftUI.View.frame(minWidth: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, idealWidth: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, maxWidth: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, minHeight: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, idealHeight: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, maxHeight: Swift.Optional&lt;CoreGraphics.CGFloat&gt;, alignment: SwiftUI.Alignment) -&gt; some&gt;&gt;.0&gt; in closure #1 () -&gt; SwiftUI._ConditionalContent&lt;SwiftUI.TupleView&lt;(Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;, Swift.Optional&lt;&lt;&lt;opaque return type of MyQrCode.QRCodeDetailView.contactInfoRow(icon: Swift.String, title: Swift.String, value: Swift.String) -&gt; some&gt;&gt;.0&gt;)&gt;, &lt;&lt;opaque return type of SwiftUI.View.cornerRadius(_: CoreGraphics.CGFloat, antialiased: Swift.Bool) -&gt; some&gt;&gt;.0&gt; in MyQrCode.QRCodeDetailView.calendarInfoDetailView(parsedData: MyQrCode.ParsedQRData) -&gt; some"
moduleName = "MyQrCode.debug.dylib"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/yc/xcodeProjects/MyQrCode/MyQrCode/Views/History/QRCodeDetailView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "281"
endingLineNumber = "281">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -382,36 +322,6 @@
endingLineNumber = "1371"
landmarkName = "openSocialApp(content:appType:)"
landmarkType = "7">
<Locations>
<Location
uuid = "081EEF9C-8A5B-4C89-8DB2-0BAC1AABA1D6 - b0c48453778d2334"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "MyQrCode.QRCodeDetailView.openSocialApp(content: Swift.String, appType: MyQrCode.QRCodeDetailView.SocialAppType) -&gt; ()"
moduleName = "MyQrCode.debug.dylib"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/yc/xcodeProjects/MyQrCode/MyQrCode/Views/History/QRCodeDetailView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "1371"
endingLineNumber = "1371">
</Location>
<Location
uuid = "081EEF9C-8A5B-4C89-8DB2-0BAC1AABA1D6 - b0c48453778d2334"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "MyQrCode.QRCodeDetailView.openSocialApp(content: Swift.String, appType: MyQrCode.QRCodeDetailView.SocialAppType) -&gt; ()"
moduleName = "MyQrCode.debug.dylib"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/yc/xcodeProjects/MyQrCode/MyQrCode/Views/History/QRCodeDetailView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "1371"
endingLineNumber = "1371">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>

@ -133,7 +133,6 @@ struct QRCodeStyleView: View {
}
}
.onAppear {
checkPhotoLibraryPermission()
initializeExistingStyle()
}
.sheet(isPresented: $showingImagePicker) {
@ -409,10 +408,9 @@ struct QRCodeStyleView: View {
}
// Logo
if photoLibraryAccessGranted {
Button(action: {
showingImagePicker = true
}) {
Button(action: {
handleCustomLogoSelection()
}) {
VStack(spacing: 8) {
if let customLogoImage = customLogoImage {
Image(uiImage: customLogoImage)
@ -448,41 +446,7 @@ struct QRCodeStyleView: View {
)
)
}
} else {
//
Button(action: {
//
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(settingsUrl)
}
}) {
VStack(spacing: 8) {
RoundedRectangle(cornerRadius: 12)
.fill(Color.red.opacity(0.2))
.frame(width: 60, height: 60)
.overlay(
Image(systemName: "exclamationmark.triangle")
.font(.title2)
.foregroundColor(.red)
)
Text("permission_required".localized)
.font(.caption)
.foregroundColor(.red)
.multilineTextAlignment(.center)
.id(languageManager.refreshTrigger)
}
.padding(12)
.background(
RoundedRectangle(cornerRadius: 16)
.fill(Color.clear)
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(Color.red.opacity(0.3), lineWidth: 1)
)
)
}
}
// Logo
ForEach(QRCodeLogo.allCases, id: \.self) { logo in
@ -754,6 +718,55 @@ struct QRCodeStyleView: View {
}
}
// MARK: - Logo
private func handleCustomLogoSelection() {
//
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized, .limited:
//
photoLibraryAccessGranted = true
showingImagePicker = true
print("相册权限已授权,显示图片选择器")
case .notDetermined:
//
print("相册权限未确定,正在请求...")
PHPhotoLibrary.requestAuthorization { newStatus in
DispatchQueue.main.async {
self.photoLibraryAccessGranted = (newStatus == .authorized || newStatus == .limited)
print("权限请求结果: \(newStatus.rawValue), 授权状态: \(self.photoLibraryAccessGranted)")
if self.photoLibraryAccessGranted {
//
self.showingImagePicker = true
}
}
}
case .denied, .restricted:
//
photoLibraryAccessGranted = false
print("相册权限被拒绝,引导用户到设置页面")
// alert
showPermissionAlert()
@unknown default:
photoLibraryAccessGranted = false
print("相册权限未知状态")
}
}
// MARK: -
private func showPermissionAlert() {
// alert
//
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(settingsUrl)
}
}
// MARK: -
private func checkPhotoLibraryPermission() {
let status = PHPhotoLibrary.authorizationStatus()

Loading…
Cancel
Save