Send Message to user on Whatsapp from app without opening Whatsapp - ios

Suppose I have few forms that needs to be filled by the user including contact number. After filling of all the forms, I want that contact number should receive a message including some greetings or some text or image clicked to use in the form. The message should be delivered as a simple SMS and also on WhatsApp. All this needs to be done without opening WhatsApp. Is it possible? If yes then how?
Thanks in advance.

I don't think this can be possible.
Yes you can set body of message using 'MFMessageComposeViewController' that involves user-interaction that means without user tapping simple message cant be sent otherwise spams could easily be written.
As far as send message via whatsApp, without opening whatsApp I guess you can only open application
NSURL *whatsAppURL = [NSURL URLWithString:#"Whatsapp://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:whatsAppURL]) {
[[UIApplication sharedApplication] openURL:whatsAppURL]]];
}
Every application has it's Own 'Sandbox' a File System that can not be access outside boundary of that app.
And on iOS 9 you have to add "Whatsapp" under a proper key in your info.plist iOS 9 not opening Instagram app with URL SCHEME

I think you should use UIActivityViewController but you need to customise it for WhatsApp and there is open source here he prepared everything :)

Related

App not opened programmatically?

I installed Meeseva app on my device. When I try to open it programmatically it's not opening.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"Meeseva App://location?id=1"]]) {
NSString *mystr=[[NSString alloc] initWithFormat:#"Meeseva App://location?id=1"];
NSURL *myurl=[[NSURL alloc] initWithString:mystr];
[[UIApplication sharedApplication] openURL:myurl];
}
When I opened fb, twitter, google+ and etc... all are opening successfully.
Can any solve this this issue?
App link is
https://itunes.apple.com/in/app/meeseva-app/id1121539928?mt=8
Is there any another way to open installed app programatically?
If your app can receive specially formatted URLs, you should register the corresponding URL schemes with the system. Apps often use custom URL schemes to vend services to other apps.
Hence "Meeseva" app might not have created a custom url for their app. So you can't do anything for it.
As mentioned above the apps which want to provide support for url schema then they have to create a custom URL schemes.
You need to find out what the correct URL scheme of the Meeseva App is. Meeseva App:// does not seem to be a valid URL scheme as it has a space in the middle.
For example the Google Maps URL scheme is comgooglemaps://, not Google Maps://
Usually developers make their URL scheme public in their documentation. However this is a feature that needs to be implemented and apps don't support this "out of the box". If the developer did not implement this, the app can't be opened via link.
Alternatively it is possible that the app reacts on "universal links". That means if there is a website for the app, iOS might ask you whether to open that website in the app or in Safari. In that case you could simply link to the website and let the user decide how the link should be opened. However, again, this needs to be implemented by the developer. If the app does not support universal links either, there's no way for you to open the app at all.

How to open a background App using a silent push from a website button

Is it possible to use a web based API push service like "Boxcar" linked to a button in my webpage, to send a silent push to my iphone in which the iphone will interrupt the currently running app, and reopen (previously opened/in background) the linked app with the push's updated info?
So in all: open an app, go to another app (such as twitter), then on my webpage press a button and have twitter interrupted and brought back to the original app with updated data from the push.
Another question would be, do I need a 3rd party API to accomplish this? or can i use purely apple code?
I am a fairly new programmer and very new to APN's and app building, so any help would be greatly appreciated. Thanks!
First off, welcome to SO!
Unfortunately, there is no way to open up applications from the background programmatically in iOS. Apple leaves that to the user. You would have to send a push to the phone that the user interacts with in order to open up the app to a specific page. The only way you can open up another app is using URL Schemes (see here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html)
The problem with that is you can only do it from YOUR app to someone else's app (or if you have a widely enough used app, some people might even link to yours, although I'm not sure Twitter would ever do that).
Basically what URL Schemes do is allow the phone to open up a URL as if it were a website. Before it loads the webpage, it checks to see if any apps respond to that URL. For instance, if you wanted to open Maps to a specific location:
NSString *title = #"title";
float latitude = 35.4634;
float longitude = 9.43425;
int zoom = 13;
NSString *stringURL = [NSString stringWithFormat:#"http://maps.google.com/maps?q=%##%1.6f,%1.6f&z=%d", title, latitude, longitude, zoom];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
Hope that answers your question!

whatsapp URL Scheme doesn't give control back to app.

I am trying to share a link via Whatsapp and have read many tutorials as well. I am able to share my link successfully but the problem is that user doesn't come back to my app after sharing on whatsapp.
Here is the code I am using to share:
NSString *referralLink = [NSString stringWithFormat:#"some link here"];
NSString *textToSend = [[NSString stringWithFormat:#"whatsapp://send?text=%#",referralLink] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *whatsappURL = [NSURL URLWithString:textToSend];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}
I know that I have to use URL Scheme to achive this and I have used it too. But I am not sure that I am using it in correct way.
Here is the screenshot of my .info file.
Behind the black bar, I have entered the bundle identifier. i.e com.abc.myapp
This is default behavior in iOS, only if the app developer of the app you are calling allows an option to send the user back to calling app will it work.
WhatsApp does not have such a feature and this is therefore not possible.
Also you should not use the whatsapp: url scheme in your apps info.plist. Doing this will make any app calling whatsapp: to open your app.
you should give your own url scheme(a unique identifier), probably your AppName. You are not supposed to use whatsapp
Now IOS 9 Do support the Apps to come back to the app when they are invoking any third party app being called using OpenURL scheme.
You can make a OS version based support at this moment unless you come to minimal support of IOS 9 for your application.

iOS open with specific apps

I'm trying to show apps from UIDocumentInteractionControllerDelegate , default apple apps like; sms, email or UIPasteBoard (Facebook and Twitter is optional) . Just like the similar of Dropbox app :
How can I handle this kind of situation? I've done already open apps from their UTI's, open just email or just sms but I don't how to show all of them in one sheet.
Thanx
I believe you're looking at an UIActivityController instead of a UIDocumentInteractionController, which I believe Apple is trying to phase out.
Check out the docs here https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html
You should try QLPreviewController. This will give you desired result.
https://developer.apple.com/library/ios/Documentation/NetworkingInternet/Reference/QLPreviewController_Class/Reference/Reference.html

Is it possible to create an MMS which contains a url link to launch a local app

I can launch my app if I embed a url in an SMS and then the user clicks on the url from within the message app. I have this all working.
What I would like to be able to do however is send an MMS to the device which contains a number of image(s) and text filling the screen and when the user clicks on the url within the MMS my app is launched same as it is if clicked from within an SMS.
Is it possible to mock this up so I can see it working? i.e. how could I create an MMS containing a working active link to demo a proof of concept (I'm not talking about creating an MMS programatically on iOS, just how to create one containing my app's url to send to the device)?
Edit: This answer was written under the assumption that implementation details were required for the URL handling part. I'll leave the technical details here for future Googlers.
Here is a link to a forum thread which seems to indicate you can't send MMSes from the iPhone programmatically (I know you said you didn't want to know this anyway, but it's here for completeness). The suggestion is to use a message provider's MMS gateway directly (e.g http://www.smsglobal.com).
Instructions on how to get a hyperlink into an MMS are here. You can just write it in plain text, or use an anchor: <a href="myapp://"> Not 100% sure the iPhone will properly parse those anchor tags in an MMS though.
Read this article. The gist is that you add a "URL types" row to your Info.plist and set it to any valid protocol, say myapp, and then a user opens a link in an MMS to a myapp URL. Article excerpt:
myapp://
myapp://some/path/here
myapp://?foo=1&bar=2
myapp://some/path/here?foo=1&bar=2
The iPhone SDK, when launching the application in response to any of the URLs above, will send a message to the UIApplicationDelegate.
If you want to provide a custom handler, simply provide an implementation for the message in your delegate. For example:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
// Do something with the url here
}

Resources