i am working on signup feature. In this feature when the user create account successfully. i am asking him or her to activate his account.
i want to open the mail application of iphone if user say yes.
now my question is simple how to open mail application from my own application?
#define URLEMail #"mailto:sb#sw.com?subject=title&body=content"
NSString *url = [URLEMail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
Try this out.
-(void)launchMailAppOnDevice
{
NSString *recipients = #"mailto:myemail#gmail.com?subject=subjecthere";
NSString *body = #"&body=bodyHere";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
stringByAddingPercentEscapesUsingEncoding and openURL are deprecated.
Now use this:
#define URLEMail #"mailto:sb#sw.com?subject=title&body=content"
NSString * encodedString = [URLEMail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: encodedString] options:#{} completionHandler:nil];
Ahoy!
The long and short of it is; you can't.
You can create an email compose view for the purpose of sending emails (see MFMailComposeViewController), but you cannot open applications arbitrarily without a purpose.
See this previous post for clarification: Launch an app from within another (iPhone)
Really though, it's not much effort for the user to close your app and open Mail so I wouldn't worry too much about it anyway.
Related
I would like to call other facetime numbers, but these are emails and not numbers. How do I do it?
For numbers, I know what to use.
NSURL *url = [NSURL URLWithString:#"facetime://+123456789"];
[[UIApplication sharedApplication] openURL:url];
But for emails, how do i change it. Any idea?
NSURL *url = [NSURL URLWithString:#"facetime://email#example.com"];
[[UIApplication sharedApplication] openURL:url];
These are the options
#"facetime://appleId" // For apple id
#"facetime://email#example.com" // For email id
#"facetime://5558675309" // For phone number
I'm trying to open a mobile configuration file (mobileconfig) in safari to install it but nothing work.
I use URL Scheme:
NSURL *finalURL = [NSURL URLWithString:[NSString stringWithFormat:#"myAppURLScheme://%#",fileName]];
BOOL canOpen = [[UIApplication sharedApplication] openURL:finalURL];
if (canOpen) NSLog(#"can open");
else NSLog(#"can't open");
log --> can open
and i try to set all the path(the file is in the Documents folder) to the file instead fileName, nothing.
how can I do it. ?
Edit1: this application do the same(open safari to install configuration)
Edit2: I think that i have to search the way to send file(any) to safari, and safari will know what to do with it.
Authorize a background task
.h file :
UIBackgroundTaskIdentifier bgTask;
.m file :
In applicationDidEnterBackground add a new background task :
bgTask = [application beginBackgroundTaskWithExpirationHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
[application endBackgroundTask:self->bgTask];
self->bgTask = UIBackgroundTaskInvalid;
});
}];
Add CocoaHTTPServer to your project
Run the server and open the .mobileconfig file :
RoutingHTTPServer *httpServer = [[RoutingHTTPServer alloc] init];
[httpServer setType:#"_http._tcp."];
[httpServer setPort:12345];
[httpServer setDefaultHeader:#"Content-Type" value:#"application/x-apple-aspen-config"];
[httpServer setDocumentRoot:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
if([httpServer start:nil])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://localhost:12345/myprofile.mobileconfig"]];
}
The mobile config file is inside your app's sandbox. Safari doesn't have access to it. The return value of [UIApplication openURL] only indicates if there was an application that understands that url scheme. It looks to me as if you're sending that url to yourself, assuming that you added myAppURLScheme as a uri handler to your info.plist file.
I think you can use data URI to encode and launch mobileconfig. (I don't have IOS device here, so I cannot test right now_
You can use http://dopiaza.org/tools/datauri/index.php to encode your profile (don't forget to add mime type: application/x-apple-aspen-config)
Then you can open:
[[UIApplication sharedApplication] openURL:dataURLGenerated];
quite had no luck either but I post this anyway if someone else can use this information. I tried opening the string via data: url which is supported by Mobile Safari, but not by openURL: – sadly.
NSString *urlHeader = #"data:application/x-apple-aspen-config;charset=utf-8,";
NSString *mobileConf = #"<?xmlversion=\"1.0\"encoding=\"UTF-8\"standalone=\"yes\"?>"
"<!DOCTYPEplistPUBLIC\"-//Apple//DTDPLIST1.0//EN\"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
"<plistversion=\"1.0\"><dict><key>PayloadUUID</key><string>A0670934-C558-42E1-9E80-9B8E079E9AB2</string><key>PayloadDisplayName</key><string>EnableTethering</string><key>PayloadDescription</key><string>EnablesTethering</string><key>PayloadOrganization</key><string>de.iphone-notes</string><key>PayloadVersion</key><integer>1</integer><key>PayloadIdentifier</key><string>de.iphone-notes.etisalat</string><key>PayloadType</key><string>Configuration</string><key>PayloadContent</key><array><dict><key>PayloadUUID</key><string>C1A41907-0CD9-4DC9-BAF1-A04A73B7E296</string><key>PayloadDisplayName</key><string>AdvancedSettings</string><key>PayloadDescription</key><string>ProvidescustomizationofcarrierAccessPointName.</string><key>PayloadOrganization</key><string>de.sendowski</string><key>PayloadVersion</key><integer>1</integer><key>PayloadIdentifier</key><string>de.iphone-notes.etisalat.apn</string><key>PayloadContent</key><array><dict><key>DefaultsDomainName</key><string>com.apple.managedCarrier</string><key>DefaultsData</key><dict><key>apns</key><array><dict><key>apn</key><string>Etisalat.ae</string><key>username</key><string></string><key>password</key><string></string><key>type-mask</key><integer>-2</integer></dict></array></dict></dict></array><key>PayloadType</key><string>com.apple.apn.managed</string></dict></array></dict></plist>";
mobileConf = [mobileConf stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *finalURL = [NSURL URLWithString:[urlHeader stringByAppendingString:mobileConf]];
BOOL canOpen = [[UIApplication sharedApplication] openURL:finalURL];
if (canOpen) NSLog(#"can open");
else NSLog(#"can't open");
For testing you can prepend http:// before data: then it will at least open in Safari and you can delete the prefix to try it. Maybe some javascript injection to remove the prefix will work; I don't know.
There is an iOS 5.0+ app, released in App Store, which displays employees profiles with their phone numbers. The users of the app can tap on the phone number and the number will be dialed on their iPhones.
The problem is that some users with iPhone 4 are reporting that it does NOT dial.
This is the code I am using to dial:
NSString *cleanedString = [[self.member.phone componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urlText = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", escapedPhoneNumber]];
[[UIApplication sharedApplication] openURL:urlText];
Any ideas about this?
There shouldn't be any / in the tel: scheme:
NSURL *urlText = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", escapedPhoneNumber]];
In the Apple URL Scheme Reference you can see some example for what is allowed in the tel: scheme.
If you use telpromt instead of tel this will return you to app after your call ends|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt:1234567890"]];
The page I want to open using twitter app:
https://twitter.com/#!/PAGE
To open twitter app I use the following code:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter://https://twitter.com/#!/PAGE"]];
[[UIApplication sharedApplication] openURL:urlApp];
But this code doesn't seem to work as expected, I got only twitter app launched without the page which i want to show.
You are looking for the following url:
twitter:///user?screen_name=PAGE
Note that Twitter is not installed on all devices. You should check the result of openURL method. If it fails, open the page in Safari with regular url.
The following code opens twitter page on twitter app if it is already installed, otherwise opens twitter on safari:
NSURL *twitterURL = [NSURL URLWithString:#"twitter://user?screen_name=username"];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL])
[[UIApplication sharedApplication] openURL:twitterURL];
else
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.twitter.com/username"]];
Don't forget to replace 'username' with your name.
I know its quite a late response to this question and I agree that, Murat's answer is absolutely correct.
Simply add a check as follows:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter:///user?screen_name=PAGE]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}
I hope this helps someone. Cheers!! :)
This is the full code required in Swift. I am using Swift 4 but i believe it is the same for Swift 3.
let Username = "YOUR_USERNAME_HERE"
let appURL = NSURL(string: "twitter:///user?screen_name=\(Username)")!
let webURL = NSURL(string: "https://twitter.com/\(Username)")!
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
application.open(appURL as URL)
} else {
// if Twitter app is not installed, open URL inside Safari
application.open(webURL as URL)
}
Don't forget to add the Info keys needed to use canOpenURL:
#Alexey: If you just want to know how to launch twitter from your application do this:
NSURL *urlApp = [NSURL URLWithString: [NSString stringWithFormat:#"%#", #"twitter://"]];
if ([[UIApplication sharedApplication] canOpenURL:urlApp]){
[[UIApplication sharedApplication] openURL:urlApp];
}else{
UIAlertView *appMissingAlertView = [[UIAlertView alloc] initWithTitle:#"Twitter App Not Installed!" message:#"Please install the Twitter App on your iPhone." delegate:nil cancelButtonTitle:nil otherButtonTitles:#"Ok",nil];
[appMissingAlertView show];
[appMissingAlertView release];
}
Hai
I am developing a new application. In that send a message to pre configured numbers and the user selecting numbers. How it is possible? when then send button is pressed. Please help. Can any give me some Sample code or tutorial.
Thank You
Please read the below SO post,
How to send SMS and number from contacts?
Here is link could help you ...
http://iosdevelopertips.com/cocoa/launching-other-apps-within-an-iphone-application.html
SMS
To open the SMS application, just use the sms: protocol in your URL:
NSString *stringURL = #"sms:";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
You can specify a phone number, but apparently not a default text for your message:
NSString *stringURL = #"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];