Skip to content
James Barrow edited this page Jan 29, 2017 · 4 revisions

SocialHelper

The social helper class allows quick access to some social aspects, such as presenting an email/message. This class has a private singleton it used for dleegate methods, so that every presenting view controller does not have to impliment them seperately.


## Singleton & Init

shared

Declaration

Swift

private static let shared = SocialHelper()

---

<br>

### init()


**Declaration**
> <sub>**Swift**</sub>  
> ```swift  
private override init()


## Scocial Methods

presentComposeViewController(serviceType:initialText:urls:images:inViewController:animated:)

Presents a compose view controller with the details passed in.

Declaration

Swift

public class func presentComposeViewController(serviceType: String, initialText: String? = nil, urls: [URL]? = nil, images: [UIImage]? = nil, inViewController viewController: UIViewController, animated: Bool = true) -> Bool


**Parameters**
<table>
<tr><td> `serviceType` </td><td> The type of service type to present. For a list of possible values, see Service Type Constants. </td></tr>
<tr><td> `initialText` </td><td> The initial text to show in the SLComposeViewController. </td></tr>
<tr><td> `urls` </td><td> The URLs to attach to the SLComposeViewController. </td></tr>
<tr><td> `images` </td><td> The images to attach to the SLComposeViewController. </td></tr>
<tr><td> `viewController` </td><td> The view controller to present the SLComposeViewController in. </td></tr>
<tr><td> `animated` </td><td> If the presentation should be animated or not. </td></tr>
<table>

**Return Value**  
Returns false if there is an issue or the service is unavailable, otherwise true.

---


<br>
## Prompt Methods  <br>

### phonePrompt(_:)
Returns a URL to call with openURL(_:) in UIApplication parsed from a number string.

**Declaration**
> <sub>**Swift**</sub>  
> ```swift  
public class func phonePrompt(_ number: String) -> URL?

Parameters

`number` The number to parse in to create the URL.

Return Value
The URL of the parsed phone number, prefixed with telprompt://.



emailPrompt(toRecipients:ccRecipients:bccRecipients:subject:messageBody:isBodyHTML:attachments:viewController:animated:)

Creates a prompt for an email with the following parameters to pass into the MFMailComposeViewController.

Declaration

Swift

public class func emailPrompt(toRecipients: [String], ccRecipients: [String]? = nil, bccRecipients: [String]? = nil, subject: String = "", messageBody: String = "", isBodyHTML: Bool = false, attachments: [(data: Data, mimeType: String, fileName: String)]? = nil, viewController: UIViewController, animated: Bool = true)


**Parameters**
<table>
<tr><td> `toRecipients` </td><td> The email addresses of the recipients of the email. </td></tr>
<tr><td> `ccRecipients` </td><td> The email addresses of the CC recipients of the email. </td></tr>
<tr><td> `bccRecipients` </td><td> The email addresses of the BCC recipients of the email. </td></tr>
<tr><td> `subject` </td><td> The subject of the email. </td></tr>
<tr><td> `messageBody` </td><td> The main body of the email. </td></tr>
<tr><td> `isBodyHTML` </td><td> Tells the MFMailComposeViewController if the message body is HTML. </td></tr>
<tr><td> `attachments` </td><td> The attachments to add to the email, passed in as a tuple of data, mime type and the file name. </td></tr>
<tr><td> `viewController` </td><td> The view controller to present the MFMailComposeViewController in. </td></tr>
<tr><td> `animated` </td><td> If the presentation should be animated or not. </td></tr>
<table>

---

<br>

### presentMailComposeViewController(toRecipients:ccRecipients:bccRecipients:subject:messageBody:isBodyHTML:attachments:viewController:animated:)


**Declaration**
> <sub>**Swift**</sub>  
> ```swift  
public class func presentMailComposeViewController(toRecipients: [String]? = nil, ccRecipients: [String]? = nil, bccRecipients: [String]? = nil, subject: String = "", messageBody: String = "", isBodyHTML: Bool = false, attachments: [(data: Data, mimeType: String, fileName: String)]? = nil, viewController: UIViewController, animated: Bool)


messagePrompt(recipients:subject:body:attachments:viewController:animated:)

Creates a prompt for a message with the following parameters to pass into the MFMessageComposeViewController.

Declaration

Swift

public class func messagePrompt(recipients: [String], subject: String = "", body: String = "", attachments: [(attachmentURL: URL, alternateFilename: String)] = [], viewController: UIViewController, animated: Bool = true)


**Parameters**
<table>
<tr><td> `recipients` </td><td> The recipients of the message. </td></tr>
<tr><td> `subject` </td><td> The subject of the message. </td></tr>
<tr><td> `body` </td><td> The main body of the message. </td></tr>
<tr><td> `attachments` </td><td> The attachments to add to the message, passed in as a tuple of attachment URL and alternate filename. </td></tr>
<tr><td> `viewController` </td><td> The view controller to present the MFMailComposeViewController in. </td></tr>
<tr><td> `animated` </td><td> If the presentation should be animated or not. </td></tr>
<table>

---

<br>

### presentMessageComposeViewController(recipients:subject:body:attachments:viewController:animated:)


**Declaration**
> <sub>**Swift**</sub>  
> ```swift  
private class func presentMessageComposeViewController(recipients: [String]? = nil, subject: String? = nil, body: String? = nil, attachments: [(attachmentURL: URL, alternateFilename: String)]? = nil, viewController: UIViewController, animated: Bool)


## MFMailComposeViewControllerDelegate Methods

mailComposeController(_:didFinishWith:error:)

Declaration

Swift

public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)


---


<br>
## MFMessageComposeViewControllerDelegate Methods  <br>

### messageComposeViewController(_:didFinishWith:)


**Declaration**
> <sub>**Swift**</sub>  
> ```swift  
public func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult)