UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Screenshot Function not working

Forums > Swift

Hi,

I have the following code in my app to detect when a screenshot is taken by a user:

.onReceive(NotificationCenter.default.publisher(for: UIApplication.userDidTakeScreenshotNotification)) { _ in Task { do { try await genFs.Save_Screenshot(RecipID: appService.Their_B_Prof.first?.UserID as? String ?? "BProfLk", RecipFirstN: passProfInfo.TheirFirstN_Swipe) } catch { print("Error: (error.localizedDescription)")

                }
            }
        }

In the XCode simulator, it takes a screenshot and shows the proper imate, but when I use it on my actual phone it just shows a white screen. Any thoughts on the cause of this?

2      

Sorry, I see that now, it didn't pickup the first piece which starts with .onRecieve

.onReceive(NotificationCenter.default.publisher(for: UIApplication.userDidTakeScreenshotNotification)) { _ in Task { do { try await genFs.Save_Screenshot(RecipID: appService.Their_B_Prof.first?.UserID as? String ?? "BProfLk", RecipFirstN: passProfInfo.TheirFirstN_Swipe) } catch { print("Error: (error.localizedDescription)") } } }

2      

Please return to your ORIGINAL post and follow directions found here.

See -> Posting Code Snips

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.