Link a button to a email address?

Discussion in 'iOS Development' started by DotSlashSlash, Oct 28, 2008.

  1. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    I know it is probably really simple but i cannot find anything in the documentation about sending a email address to the mail and application and opening up the mail application with a new email.

    its hard to explain but i think it have seen it before.

    so basically on my application i want it so when you press a button it closes my application and opens up mail with a new email which has a specified email address in it.

    All i really need is the function,

    Thanks,
    JackMcLean
  2. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    i thought i saw that in one of apples sample source codes I could be wrong have you had a look at them????
  3. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    Code:
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:<email-address>"]];
    Also it is in the docs. search for mailto
  4. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    thanks alot!!

    Please Register or Log in to view images



    and no i cant find anything in the documentation in xcode which has anything with mailto in, have you got the 2.1 SDK?
    ------------------double post merged------------------
    also it probably me being stupid but how do you define an action to a UIButton i know how to with a UIBarButtonItem because you can use initWithTitle etc. but how do you do it with a UIButton?
  5. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    Code:
    UIButton *button1 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    [button1 addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside];
    
    
    Then u make the action

    Code:
    -(void)button1:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:<email-address>"]];
    }
    
    also its the first item that pops up when u do a doc search should say mail links
  6. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)

    Please Register or Log in to view images

    thanks for the help,
    Do you by any chance know how to remove the reflection on an icon aswell? I think it is in the info.plist but i am not sure how plists work

    in the iTunes Connect Developer Guide it says
  7. ipodtouchmaster05

    ipodtouchmaster05 Well-Known Member

    Joined:
    Sep 30, 2007
    Messages:
    1,787
    Likes Received:
    41
    Device:
    iPhone 5 (Black)
    in your info.plist add this:
    <key>UIPrerenderedIcon</key>
    <plist>
    </true>
    </plist>

    That might be it, im not 100% sure but its worth a try
  8. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    i think in the info.plist add a new item then make the key UIPrerenderedIcon and make the string NO
  9. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    back to the UIButton, does that mean that the action does not need to be declared in the .h file.

    i dont really understand because in the first part you have set the button as the action
    ___________________
    also i found this post on the apple forums: http://discussions.apple.com/thread.jspa?threadID=1748639&tstart=0

    you set the value type of the array (i think is the right term) to boolean and then tick the box, or just write <true/> in a text editor.
  10. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    yeah if u code the button by hand then it dosn't need to be declaired in the .h if u made it in IB then it does need to be

Share This Page