Can I use whatsapp in my app for sending message - iphone

I want to use whatsapp in my app to send message to other phone. I have seen this public API for whatsapp on Github, here. But I dont find that API for iOS. So is that possible to use whatsapp in iOS app? And is that legal? And where can I find public API of whatsapp for iOS?

yes, you can use the whatsapp for sending text/ images through you ios app.
there are two ways to do so
1. URL scheme
NSURL *whatsappURL = [NSURL URLWithString:#"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
UIDocumentInteraction
see the link below
http://www.whatsapp.com/faq/en/iphone/23559013

Yes you can through :
URL scheme
UIDocumentInteraction
As #NSAnant mentioned
Just in case you are coding an hybrid app (Cordova,phonegap,etc) a simple anchor with the URL Scheme from Whatsapp FAQ will solve the issue (integrate WhatsApp into my app)
Send Whatsapp Friendly Message

Is as simple as this. Hope it helps ;-)
NSURL *whatsappURL = [NSURL URLWithString:#"whatsapp://send?text=Hello%20world"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
//WhatsApp is installed in your device and you can use it.
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
//WhatsApp is not installed or is not available
}

in iOS 9 : you need to Set key in info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
<string>twitter</string>
<string>whatsapp</string>
<string>wechat</string>
<string>line</string>
<string>instagram</string>
<string>kakaotalk</string>
<string>mqq</string>
<string>vk</string>
<string>comgooglemaps</string>
</array>
After set key, below code is working in iOS 9.
NSString * msg = #"mahesh";
NSString * urlWhats = [NSString stringWithFormat:#"whatsapp://send?text=%#",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"WhatsApp not installed." message:#"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}

No This is not legal. you cant use watsapp in your app.

Related

iPhone 4 problems dialing from inside app

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"]];

How to start map application on iPhone from objective c

I develop app for IOS 6.
I want to run maps application and pass it start and destination so I can navigate user.
UIApplication *app = [UIApplication sharedApplication];
NSString *coordinates = [NSString stringWithFormat:#"http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f", ...];
[app openURL:[NSURL URLWithString: coordinates]];
I thought that this code will open google maps in browser on simulator, and maps app on device, but on the device it runs browser google map.
Am i doing something wrong?
If you're not aware, Apple no longer uses Google maps so you have to use their new URL scheme for the Apple maps.
(Note: if you're supporting iOS 5, then you should use both. The google maps scheme and apple maps)
Here is an example query http://maps.apple.com/maps?daddr=San+Francisco,+CA&saddr=cupertino
Here is the documentation for it: Apple Maps URL Schemes
Another option, if you have an MKPlacemark object:
// placemark is your MKPlacemark object
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:placemark];
if([destination respondsToSelector:#selector(openInMapsWithLaunchOptions:)])
{
// Using iOS6 native maps app
[destination openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
else
{
// Using iOS5 which has the Google Maps application
NSString *currentLocation = #"Current%20Location";
NSString *routeString = [NSString stringWithFormat:#"%#saddr=%#&daddr=%#", kMapsBaseUrl, currentLocation, address.mapAddress];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:routeString]];
}
This is what I use on iOS 8.
First I try to open the url #"comgooglemaps://", if it works this means that they installed the google maps app, so then I can open the app.
If it doesn't work then the app isn't there, just open google maps in Safari.
In both cases it passes the query q=London.
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"comgooglemaps://"]]){ //open google maps app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"comgooglemaps://?q=London"]];
}
else{ //open browser
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://maps.google.com/maps?q=London"]];
}
-(void)openAddressOnNativeMapApp{
NSString *addressOnMap = #"cupertino"; //place name
NSString* addr = [NSString stringWithFormat:#"http://maps.apple.com/?q=%#",addressOnMap];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
For More Info visit Apple Doc for open native map App

How to open iphone mail application from my own application?

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.

How to open twitter page in twitter app from my iphone app?

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];
}

sending message to pre configured numbers

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];