Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

send email swiftui

struct MailView: UIViewControllerRepresentable {

    @Binding var isShowing: Bool
    @Binding var result: Result<MFMailComposeResult, Error>?

    class Coordinator: NSObject, MFMailComposeViewControllerDelegate {

        @Binding var isShowing: Bool
        @Binding var result: Result<MFMailComposeResult, Error>?

        init(isShowing: Binding<Bool>,
             result: Binding<Result<MFMailComposeResult, Error>?>) {
            _isShowing = isShowing
            _result = result
        }

        func mailComposeController(_ controller: MFMailComposeViewController,
                                   didFinishWith result: MFMailComposeResult,
                                   error: Error?) {
            defer {
                isShowing = false
            }
            guard error == nil else {
                self.result = .failure(error!)
                return
            }
            self.result = .success(result)
        }
    }

    func makeCoordinator() -> Coordinator {
        return Coordinator(isShowing: $isShowing,
                           result: $result)
    }

    func makeUIViewController(context: UIViewControllerRepresentableContext<MailView>) -> MFMailComposeViewController {
        let vc = MFMailComposeViewController()
        vc.mailComposeDelegate = context.coordinator
        return vc
    }

    func updateUIViewController(_ uiViewController: MFMailComposeViewController,
                                context: UIViewControllerRepresentableContext<MailView>) {

    }
}
Comment

send email swiftui

struct ContentView: View {

    @State var result: Result<MFMailComposeResult, Error>? = nil
    @State var isShowingMailView = false

    var body: some View {

        VStack {
            if MFMailComposeViewController.canSendMail() {
                Button("Show mail view") {
                    self.isShowingMailView.toggle()
                }
            } else {
                Text("Can't send emails from this device")
            }
            if result != nil {
                Text("Result: (String(describing: result))")
                    .lineLimit(nil)
            }
        }
        .sheet(isPresented: $isShowingMailView) {
            MailView(isShowing: self.$isShowingMailView, result: self.$result)
        }

    }

}
Comment

PREVIOUS NEXT
Code Example
Swift :: how to loop in swift 
Swift :: swift switch statement 
Swift :: two variable sum in swift 
Swift :: Swift Named Tuples 
Swift :: swift protocols 
Swift :: check if UIView is UIButton or UILabel not 
Swift :: how to add dragdown gesture recognizer on view 
Swift :: repeat...while Loop Swift 
Swift :: declaration of array in swift by two methods. 
Swift :: Swift Weak Reference 
Swift :: swift print struct name 
Swift :: Swift Named Tuple 
Swift :: parsing to double any data type in swift 
Swift :: swift reading binary data 
Swift :: Why Inheritance? 
Swift :: how to call another view controller method when button click from another ios swift 
Swift :: swiftui slide menu 
Swift :: Swift Benefits of Using Functions 
Swift :: swift uitextfield only numbers keyboard lock programmatically 
Swift :: swift 5 on return button action 
Swift :: So, because promart depends on both flutter_test from sdk and freezed ^1.1.1, version solving failed. [ ] FINE: Exception type: SolveFailure 
Swift :: how to do corner radius from button image in swift 
Ruby :: rails get list of tables 
Ruby :: activerecord list tables 
Ruby :: how to check ruby version 
Ruby :: rails g controller 
Ruby :: remove first element from an array ruby 
Ruby :: edit file terminal mac 
Ruby :: how to link to with font awesome rails 
Ruby :: iterate through values of an object rails 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =