How to share app - iphone

I'm developing an app. I'm going to publish to an app store. But client needs to share this app with friends. I have a button to share my app. How to share the app? I read some doc they mentioned, use [[UIApplication SharedApplication] openURL:#" url"]. I don't have my app URL. Because I didn't submit the app. Is it possible to share my app?

If you want to know what the URL of your application will be before it has been submitted/approved, Apple provides a shorthand URL you can use, of the form:
http://itunes.com/apps/appname
For example:
http://itunes.com/apps/AngryBirds
If you want the specific URL with the application ID, you could submit v1.0.0 without the "Share" link, then immediately submit a 1.0.1 update with the link included.

Url can be generated via app id. Its the best way to do it coz if app name changes, url could change. But app id wont change.
You can get your app id on itunesConnect.apple.com or via itunes.
//https://itunes.apple.com/app/id_hereisyourappID
Let see how to do the sharing.
I will show you 4 ways to share your link. Via Facebook, Twitter, Mail and SMS.
For Facebook and Twitter.
Add Accounts and Social framework. And in your header import.
#import <Social/Social.h>
#import <Accounts/Accounts.h>
when you want to share link use the following code
SLComposeViewController *mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];//for twitter use SLServiceTypeTwitter
[mySLComposerSheet addURL:[NSURL URLWithString:#"https://itunes.apple.com/app/id123456789"]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
Lets do it with mail add MessageUI framework and import
#import <MessageUI/MessageUI.h>
And the delegate MFMailComposeViewControllerDelegate
in your code
MFMailComposeViewController* mailComposer = [[MFMailComposeViewController alloc] init];
[mailComposer setMailComposeDelegate:self];
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setMessageBody:#"https://itunes.apple.com/app/id123456789" isHTML:NO];
[self presentViewController:mailComposer animated:YES completion:nil];
And add delegate method
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
You can create html content for mail body.
Lets share it via SMS
Add delegate MFMessageComposeViewControllerDelegate
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"https://itunes.apple.com/app/id123456789";
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
And add delegate method.
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[controller dismissViewControllerAnimated:YES completion:nil];
}
I hope this helps.

Related

Obj C Modal box with options to call or email

Hi everyoneI need some direction on how to go about accomplishing a task. I have a app with 5 tab bar items I need to program one of the tabs to call a modal dialog box that has three options. 1. Cancel 2. Call Us 3. Email Us. if the user pushes call us the device should start calling our 800 number if they press email us then it should open the email client and put our sales or support team automatically in the "to:" section. Please provide me with some direction or perhaps a tutorial on how to something like this. Thank you for your help.
I have added these tasks in a different view using two UIButtons. if you come up with a way to do a popOver please let me know. If not I will go with what I have. Thank you. The code I used for email and call (both can be found by doing a SO search) in case anyone else looks in on this thread are as follows:
EMAIL
-(IBAction)emailUs:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailViewcontroller = [[MFMailComposeViewController alloc]init];
mailViewcontroller.mailComposeDelegate = self;
[mailViewcontroller setToRecipients:[NSArray arrayWithObjects:#"CustomerService#laserpros.com", nil]];
[mailViewcontroller setTitle:#"Email Us"];
[mailViewcontroller setSubject:#"Email Us"];
[mailViewcontroller setMessageBody:#"Your message goes here" isHTML:NO];
[self presentViewController:mailViewcontroller animated:YES completion:nil];
}
else
{
NSLog(#"Device is unable to send email in its current state.");
}
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
CALL
-(IBAction)callUs:(id)sender
{
NSURL *phoneNumber = [NSURL URLWithString:#"telprompt://18885585277"];
[[UIApplication sharedApplication] openURL:phoneNumber];
}

how to display app name in place of "ios" during facebook sharing

I am using this code the sharing happens but it shows ios as the application.How can it display my application name ?
- (IBAction)postToFacebook:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:#"First post from my iPhone app"];
[self presentViewController:controller animated:YES completion:Nil];
}
}
You have to register your app on Facebook for that and have to share through Facebook SDk ( not Social framework).
Facebook sdk tutorial is here

Attach a picture to twitter post

How can I attach a picture to a twitter post like the iPhone built in photo app does?
If any body has some samplecode that will be a great help.
Thanks.
The other answers are suggesting TWTweetComposeViewController, however you should if you can avoid using this class, it's now deprecated in iOS 6,
Please see here: TWTweetComposeViewController deprecated in IOS6
And from Apple themselves, WWDC 2012, session 306 presentation PDF:
Twitter Framework
• Twitter framework is deprecated
• Do not use TWTweetComposeViewController
To use Twitter now you should use the SLComposeViewController class of the Social framework, it's usage is almost identical to TWTweetComposeViewController.
You may need to support iOS 5, in which case you have no other option then to use the TWTweetComposeViewController class, but you should make the effort to check for SLComposeViewController and use that if it's available, simply because this will save you time and effort in the near future when support for iOS 5 is dropped, the TWTweetComposeViewController class really may be gone. If you rely on the Twitter framework now for simplicity as it does work on iOS 5 and 6, you're being short sighted and you will have problems sometime later, it's only a few more lines to do this and it will mean you won't need to worry about future iOS SDK releases.
You should import Twitter.framework and Social.framework, mark them both as optional imports (not required).
Example code:
UIImage *myImage = [...]; // an image
if( NSClassFromString(#"SLComposeViewController") ){
// We have the Social framework in our iOS system
// iOS 6 and later will use this
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]){
SLComposeViewController *twitterCompose = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterCompose addImage:myImage]; // Adding your UIImage
twitterCompose.completionHandler = ^(SLComposeViewControllerResult result){
// Handle result, dismiss view controller
[self dismissViewControllerAnimated:YES
completion:nil];
};
[self presentViewController:twitterCompose
animated:YES
completion:nil];
}else{
// the user does not have Twitter set up
}
}else if( NSClassFromString(#"TWTweetComposeViewController") ){
// We don't have the Social framework, work with the Twitter framework
// iOS 5 only will use this
if( [TWTweetComposeViewController canSendTweet] ){
TWTweetComposeViewController *twitterCompose = [[TWTweetComposeViewController alloc] init];
[twitterCompose addImage:myImage];
twitterCompose.completionHandler = ^(TWTweetComposeViewControllerResult result){
// Handle result, dismiss view controller
[self dismissViewControllerAnimated:YES
completion:nil];
};
[self presentViewController:twitterCompose
animated:YES
completion:nil];
}else{
// the user hasn't go Twitter set up on their device.
}
}else{
// Wow you're going retro with this app,
// you must be on iOS 4 if you ever get here...
}
Here how i use it:
NSLog(#"Ready to Tweet.");
TWTweetComposeViewController *tweetComposer = [[TWTweetComposeViewController alloc] init];
[tweetComposer setInitialText:[NSString stringWithFormat:#"My message"]];
[tweetComposer addImage:[UIImage imageNamed:#"114x114"]];
[tweetComposer addURL:[NSURL URLWithString:#"http://myPage"]];
tweetComposer.completionHandler = ^(TWTweetComposeViewControllerResult result){
if(result == TWTweetComposeViewControllerResultDone){
NSLog(#"Tweeted.");
} else if(result == TWTweetComposeViewControllerResultCancelled) {
NSLog(#"Cancelled.");
}
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
};
[self presentModalViewController:tweetComposer animated:YES];
if you are using ios 5.0 then you can directly post image like
Add Framwork twitter.framework
import Twitter/TWTweetComposeViewController.h
-(void)postToTwittert
{
Class TWTweetComposeViewControllerClass = NSClassFromString(#"TWTweetComposeViewController");
if (TWTweetComposeViewControllerClass != nil) {
if([TWTweetComposeViewControllerClass respondsToSelector:#selector(canSendTweet)]) {
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
[twitter setInitialText:#"text"];
[twitter addImage:[UIImage imageNamed:#"imagename"]];
[twitter addURL:[NSURL URLWithString:#"http://www.google.com"]];
[self presentViewController:twitter animated:YES completion:nil];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
if(res == TWTweetComposeViewControllerResultDone)
{
NSLog(#"success for twitter post");
}
else if(res == TWTweetComposeViewControllerResultCancelled)
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Canceled" message:#"Your Tweet was not posted" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
[self dismissModalViewControllerAnimated:YES];
};
}
}
}
call this function where you wants twitter post
and do appropriate changes that you want..
Best luck..
I just use UIActivityViewController to post to Twitter now.
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:#[#"Default Text", [UIImage imageNamed:#"imageName"]] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
This will present a controller where the user can decide what to do (Post to Twitter, Post to Facebook, etc...)
It then uses the system tweet sheet etc... to do it.
You don't have to provide the default text. This can be overwritten anyway.
Oh, also, no frameworks required for this.

MFMailComposeViewController does not send mail

I am trying to send mail using MFMailComposeViewController. Everything works, except that mails do not get sent, and I always get MFMailComposeResultFailed.
Any pointers? I am NOT using the simulator, and sending mail does work from my device. I do have a connection (testing via Reachability), and [MFMailComposeViewController canSendMail] returns YES.
No compiler warnings in the project, no crashes...
It was a bug in IOS4.
I had both an Exchange mail account and an old, inactive IMAP account on my phone. Apparently, that leads to problems with iOS4. The mails actually were stuck in the outbox. Once I removed the inactive IMAP account, everything worked as expected.
Some readers might be facing this problem:
Make sure you implement the <MFMailComposeViewControllerDelegate> protocol
Here's the code:
// in TestViewController.h
#interface TestViewController : UIViewController<MFMailComposeViewControllerDelegate>
#end
// in TestViewController.m
#interface TestViewController ()
#end
#implementation
- (void) compose {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello there"];
[picker setToRecipients:#[]];
// Fill out the email body text
NSString *emailBody = #"Hello, sending a message from my app";
[picker setMessageBody:emailBody isHTML:NO];
// use this function. presentModalViewController:... is deprecated
[self presentViewController:picker animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
It's difficult to tell without seeing a code snippet, however you should check the following:
1) you have correctly set the MFMailComposeViewController's delegate and implemented its delegate methods;
2) you have set the mail subject using setSubject:
3) you have set the message body using setMessageBody:isHTML:
and optionally set an attach using addAttachmentData:mimeType:fileName:
4) you have presented to the user your mail compose view controller using something like
[self presentModalViewController:mcvc animated:YES];
Hope this helps.

Mail send framework for iphone

I want to send emails with attachments from my iphone application with custom UI. What can i use for this?
UPD: maybe it's possible to use some smtp library for this task? What can you advice?
you need to do the following
first add a framework by right clicking on project.
Add -> Existing Framework ->
library/frameworks/MessageUI.framework
then
in ViewController.h file
#import <MessageUI/MessageUI.h>
#interface ViewController : UIViewController <UITextFieldDelegate, MFMailComposeViewControllerDelegate>{
//....yor variables
}
ViewController.m file
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Sample Email Application"; // title of navigation bar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:#selector(composeMail:)] autorelease]; // for adding a compose button
//in navigation bar.
//...your code
}
-(void) composeMail: (id) sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTintColor:[UIColor blackColor]];
[picker setSubject:#"Sample Email Application"];
[picker setMessageBody:[NSString stringWithFormat:#"Visit for more help %#. ",#"http://google.com"] isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[controller dismissModalViewControllerAnimated:YES];
}
You will need to compile in your own SMTP server, there are a few online that work. This is a pile of hurt. Just use the iPhones Message Composer which is standard. Unless you are building a email spam client this wont really work.
If you want to send email without using the native mail composer UI and without setting up your own SMTP server, you can check out PostageApp (http://postageapp.com/). There's an iOS / Mac API wrapper that lets you send email through the API. https://github.com/postageapp/postageapp-objc
(Disclosure: I work for PostageApp and developed the plugin.)
The open source three20 framework has designed it's own Mail capabilities via TTMessageController which mimics the original Mail app..You can use that as a starting point and then simply modify the UI of it to your needs.
E-mailing attachments is another story though...
More information: http://www.three20.info/overview