How can I directly send a form to a email address through iOS app? - swift4

I want to send a email directly from a iOS app to a email address.
I'm trying to integrate this package, but the package is unable to install.
https://github.com/onevcat/Hedwig
I need to send a form as a email.

1) add MFMailComposeViewControllerDelegate in your class delegate
add the following code in a func
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients([email ?? ""])
composeVC.setPreferredSendingEmailAddress(someEmail ?? "")
// composeVC.setSubject("Message Subject")
composeVC.setMessageBody("Checking", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
Then Add this function to go back to app when email view dismiss
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult, error: Error?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}

If you want to send an email from the app, you need to show a View (like the MailComposer). Apple wont let you send emails in the background. The user needs to know that you're sending an email. Hedwig seems to work, but for server side.
Quote annotation from Hedwig's site:
Can I use it in iOS? At this time Swift Package Manager has no support
for iOS, watchOS, or tvOS platforms. So the answer is no. But this
framework is not using anything only in iOS (like UIKit), so as soon
as Swift Package Manager supports iOS, you can use it there too.

Related

How can I exract information to convert to vcard

I am creating an app using swift in xcode 10 that would allow user to create digital portfolios viewed in UIview, this UI view will contain their names , portfolio links and other stuff related to their profession. I have not done anything on it yet, I just want to know how can I extract data from the view to convert to vcard so I can share it
So if get it correctly you will have an application that lets a user fill in his information and create a digital portfolio, after that you want to the user to able to share the information outside of the app. I am not exactly sure what you mean by "extract" but on iOS using swift you can share information like this.
Inside your viewController:
override func viewDidLoad() {
super.viewDidLoad()
let items: [Any] = ["Put whatever you want to share in here", URL(string: "https://www.apple.com")!]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
self.present(ac, animated: true)
}
This will bring up the activity controller.

Sending an SMS/iMessage programmatically in Swift [duplicate]

This question already has answers here:
How to programmatically send SMS on the iPhone?
(18 answers)
Closed 4 years ago.
I’ve seen many things that mention using MessageUI Framework for COMPOSING messages, but is there a way to automate SENDING it in Swift? Perhaps even allowing my code to run once the Send Button is pressed, then I call the actual method to send it.
You can't just send a message without user's confirmation, but you can present the MFMessageComposeViewController at any time you want.
import MessageUI
func sendSMS(with text: String) {
if MFMessageComposeViewController.canSendText() {
let messageComposeViewController = MFMessageComposeViewController()
messageComposeViewController.body = text
present(messageComposeViewController, animated: true, completion: nil)
}
}

How to programmatically show a window/view controller in Swift 4 for macOS application

I'm trying to programmatically show a window in my macOS application. The reason I want to do it programmatically is because the user clicks a Login button and the resulting function depends on the success of the login. If it was successful, the window is shown; otherwise, it is not.
Here is a screenshot of my Xcode window:
Here's what I'm trying in the code (Alert is a class I created to make showing NSAlert dialogs easier):
#IBAction func btnLogin_Click(_ sender: Any) {
let email = txtEmail.stringValue
if(email.isEmpty) {
Alert.show(parent: view.window!, message: "Email is required.")
return
}
let password = txtPassword.stringValue
if(password.isEmpty) {
Alert.show(parent: view.window!, message: "Password is required.")
return
}
// this does not work, even though I gave the window and view controllers
// both identifiers in the storyboard
self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("wcStores"))
}
Apple's documentation for NSStoryboard.SceneIdentifier is pretty much nonexistent, and other methods I've seen seem to pertain to earlier versions of Swift.
What am I doing wrong?
Alright, so this is not what I originally was trying to do, but this way is much better, and what I was really looking for.
let vcStores = self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("vcStores"))
as! NSViewController
self.view.window?.contentViewController = vcStores
This will just replace the window's contents with the contents in the view vcStores as defined in Interface Builder.
This video also helped, albeit for iOS and Swift 3. I was trying to create a new NSWindow at first because I'm so used to doing desktop development in Java Swing or C# Windows Forms. But I love how easy it is to just switch out the window contents like this.

Memory Management When Navigating Between View Without Using Navigation Controller

I have been working on iOS application in swift from last 40-45 days. It has around 20 screens. I have implemented google map, payment gateway and many other UI component into it.
My problem is it is showing memory usage around 120 MB in flows which is very high for mobile devices. I did not used navigation controller and I have created all UI component programmatically.
In order to move from one view to another view, I have connected them via segue and in prepare for segue method I am sending data if needed. Given code is moving from one view to another
#IBAction func goToSearchFromHome(searchButton: UIButton) {
self.performSegueWithIdentifier("homeToSearchSegue", sender: self)
}
In order to come on previous page I am using following code:
#IBAction func goToHomePage(homeButton: UIButton) {
let vc = storyboard!.instantiateViewControllerWithIdentifier("homeScreen")
self.presentViewController(vc, animated: true, completion: nil)
}
Ideally, when moving from one screen to another, memory usage should include on that instance of view. What should I do in order to solve my problem?

Swift, unable to reload chat window using JSQMessagesViewController

My app allows users to view another users info by tapping their avatar, at which they can block that user so that their message content is not visible.
What is the best way when returning to the chat view to clear the messages and reload them?
This would allow my blocking code to work on the fly. Currently it works when I dismiss the chat view and return but not when jump to another view and then back to the chat view.
Ive tried self.collectionView!.reloadData() but that does not do anything.
All you need is to implement
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.collectionView?.reloadData()
}
that is called when you come back from an already instantiated view.
Call the reloadData method after a delay.
self.performSelector(#selector(self.delayReload), withObject: nil, afterDelay: 0.1)
func delayReload() {
self.collectionView.reloadData()
}
Hope this will help you.
Sincerely,
Harri.