iOS Tutorial Mails and SMS messages

Discussion in 'iOS Tutorials' started by Erel, Oct 27, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    MailComposer and MessageComposer types from the iPhone library allow the user to send mails and SMS messages from your app. The users will see a pre-filled form which they can modify and send.

    (press on the small gear button and set the quality to HD)


    Not all devices support these two features. You should check whether the feature is supported or not. In this example it is done with this code:

    Code:
    mailButton.Enabled = mailc.CanSendMail
    smsButton.Enabled = smsc.CanSendText
    The next step is to dim and initialize MailComposer or MessageComposer, fill the fields and show the composer:
    Code:
    Private Sub SendMail
       
    'always dim and initialize the MailComposer before you use it
       Dim mailc As MailComposer
       mailc.Initialize(
    "mailc")
       mailc.SetToRecipients(
    Array("hello@example.com""world@example.com"))
       mailc.SetSubject(
    "This is the subject")
       mailc.SetBody(
    "This is the <b>body</b>."True)
       
    'create a file and add it as an attachment
       File.WriteString(File.DirTemp, "1.txt""hello world")
       mailc.AddAttachment(
    File.DirTemp, "1.txt""text/plain")
       mailc.Show(Page1)
    End Sub
    The Complete event will be raised with the result:
    Code:
    Sub Mailc_Complete (Result As Int)
       
    If Result = mailc.RESULT_SENT Then
         hd.ToastMessageShow(
    "Message sent"True)
       
    Else
         hd.ToastMessageShow(
    "Message was not sent"True)
       
    End If
    End Sub
    The project is attached.
     

    Attached Files:

  2. miker2069

    miker2069 Active Member Licensed User

    Is it possible to send an email or sms autmatically without showing the email or sms UI?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    No.
     
  4. AndrewChan0513

    AndrewChan0513 Member Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

    It is better to post it in the wishlist forum. Though features (especially non-simple features) that are only relevant for jailbroken devices are less likely to be implemented in the near future.
     
  6. Dan Harding

    Dan Harding Member Licensed User

    How do you call a phone number or send an address to the map app?

    I've found half of the answer - this will open a browser to display a map:

    Dim addr, url As String
    addr = pAddress
    addr = addr.Replace(" ", "+")
    url = "https://www.google.com/maps/place/" & addr
    Main.App.OpenURL(url)

    where pAddress is a parameter containing a street address and Main is the initial object of the app.
     
    Last edited: Apr 10, 2015
  7. JanPRO

    JanPRO Well-Known Member Licensed User

    Code:
    If App.CanOpenURL("tel:") = True Then
    App.OpenUrl(
    "tel:123")
    End If

    'OR

    If App.CanOpenURL("telprompt:") = True Then
    App.OpenUrl(
    "telprompt:123")
    End If
     
    Dan Harding likes this.
  8. Francesco AB

    Francesco AB New Member Licensed User

    Do you have something for Android as well?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this in the B4A forum.
     
  10. Douglas Farias

    Douglas Farias Expert Licensed User

    @Erel
    How can i remove the message "Sent by my iphone" from body?
    i dont add this text, iphone add automatic. can i remove this mensage ?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    It is added by the mail app. You need to remove it from the mail app settings.
     
    Douglas Farias likes this.
  12. valentino s

    valentino s Active Member Licensed User

  13. marcick

    marcick Well-Known Member Licensed User

    Hi Erel, could you please explain better "Not all devices support these two features. You should check whether the feature is supported or not" ?
    I need to send SMS.
    Can I be sure that this function will work on any device that is able to normally send SMS ?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    The purpose of this code is to enable the feature only if it is supported:
    Code:
    mailButton.Enabled = mailc.CanSendMail
    smsButton.Enabled = smsc.CanSendText
    CanSendMail and CanSendText methods are supported on all devices.
     
  15. marcick

    marcick Well-Known Member Licensed User

    So, only devices that doesn't have a SIM card, or devices that have SIM card but not SMS enabled (data only) will return false with smsc.CanSendText.
    All other devices will be able to send SMS with MessageComposer.
    Correct ?
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Yes (most iPads don't have a SIM card).
     
    marcick likes this.
  17. wl

    wl Well-Known Member Licensed User

    Is tehre a way to keep the mail app open so I can add info to the contents of the email ?
    It seems the mail gets sent immediately ?

    Tx
     
  18. marcick

    marcick Well-Known Member Licensed User

    The email is not sent until the user click the send button, so he can add anything he likes in the body before sending.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice