objective c - Open with suggestions when trying to open URL schemes - ios

I started an application that can handle SMS or Mail url schemes but I don't want to open the default apps installed. I have tried doing this
[[UIApplication sharedApplication] openURL: url];
but this opens the default SMS and Mail apps.
I tried using the UIActivityViewController
NSString *url=#"mailto:sample#gmail.com";
NSURL *schemeURL = [NSURL URLWithString:url];
NSString * title =[NSString stringWithFormat:#"Send Email",url];
NSArray* dataToShare = #[url];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil]
but this doesn't prefill the recipient field with the specified email.
It would be nice if the behaviour is the same with UIActivityViewController but let's us prefill information such as recipient.
Any suggestions ?

You can use non-default apps on macos but I don't think you can do so on iOS. Have a look at e.g. https://developer.apple.com/documentation/uikit/uiapplication/1648685-openurl?language=objc .
You could try with a URL similar to below to send with a given subject and body.
#"message://mailto://sample#gmail.com?subject=Subject&body=Body"
I think if you drop the message bit it will still work. I use it like that inside a HTML page inside an app somewhere.
If you need any special characters you will have to encode them in the subject and body.

Related

Launch app from calendar event

I've seen similar question here. But it doesn't work for me. I've added my url scheme with calendar event's url property. It's pretty cool to see scheme url appeared in event's url row. But I couldn't tap on url(url scheme) as like normal url like www.google.com.
code for adding url to EKEvent
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"Event Test For adding url";
NSString *customURL = #"sampleEventappScheme://";
event.URL = [NSURL URLWithString:customURL];
After event added to calendar event, see screenshot for better understanding.
Note: If I try to launch app with safari using this scheme, It's perfectly worked. So there's no issue with scheme configuration.
I've resolved this issue by just extend url by event title with our app url scheme. ie. We just make it as url that is enough.
NSString *customURL = #"sampleEventappScheme://title=eventadd";
Brief explanation:
This is normal url : http://www.google.com. Here http is url scheme. As like that, in above app url, sampleEventappScheme is url scheme. When we try to hit this url, system will see scheme lookup table, if we already register our scheme, then it will switch to our app.

Custom Login Instagram API iOS

I'm developing an application for iOS with the authentication, using Instagram API.
My code for authentication works good:
NSString *fullURL = [NSString stringWithFormat:#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=code",KCLIENTID,kREDIRECTURI];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
instagramConnectWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];
instagramConnectWebView.delegate = self;
[instagramConnectWebView loadRequest:request];
When the request is sent, my webView shows the standard Instagram login interface, where user has to insert username and password to login. If login succeed, app is redirected to my redirection-url, where i get the code and the token of this user.
My question is really simple, is there a way to customize standard interface of Instagram login? I'd like to insert in my app two simple UITextField (One for username and one for the password) and when user clicks on my UIButton login, application should send (POST or GET?) username and password to Instagram, and return response (Login success or not).
I hope i explained myself.
Thanks.
You can make this by using javascript. by loading a web view in background :
You need to access the text field of that web view and pass value of your custom UItextfields and after that you can call webView's "Submit" button's Onclick event.
NSString *javaScript = #"document.getElementById('id_username').value = 'tfusername'";
NSString *javaScript2 = #"document.getElementById('id_password').value = 'tfpassword'";
to evaluate each script you can call: [webView stringByEvaluatingJavaScriptFromString:javaScript];
You can also call script to press login button. This same thing work for me. May be this will help you.
I have created a wrapper for Instagram API for iOS. Take a look at this link . This will also give an idea of what you need to do.

How to pass query string parameters when sharing a link through Facebook iOS SDK?

I am running into difficulty sharing an article link from my iOS app to Facebook using the Facebook SDK FBWebDialogs class. The URL of the link includes query string parameters, which I am URL encoding from my iOS app before sending to Facebook.
Here is an example link that I am trying to share:
http://www.foo.com/message.html?s=This%20is%20a%20test%20&%20an%20example
Here is what Facebook shows as the link on my timeline:
?s=This+is+a+test+&+an+example
Once the link is published to my Facebook timeline, Facebook appears to be stripping all URL encoding, leaving my query string void of encoding, which causes the destination web app to not receive necessary data. Needless to say, the destination webpage has trouble consuming the query string parameters properly if special characters (&, =, etc) are not encoded properly when linked within the Facebook feed.
What is the proper way to share a link with querystring parameters? Should querystring params be passed as a separate parameter, or should they be denoted somehow within the link url?
Below is the code relevant to setting up the share parameters.
NSString *url_param_str = [NSString stringWithFormat:#"http://www.foo.com/message.html?s=%#", #"This is a test & an example"];
NSString *web_url_param_str = [url_param_str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *feedParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"Sharing an article", #"name",
#"This is a test title", #"description",
#"www.foo.com", #"caption",
web_url_param_str, #"link",
nil];
It looks like that Facebook has decided to scrub url query parameters when using the SLComposeViewController You have to use Facebook Share now.
https://stackoverflow.com/a/32263392/608739
#import <FBSDKShareKit/FBSDKShareKit.h>
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL urlWithString:#"http://www.foo.com/message.html?s=This%20is%20a%20test%20&%20an%20example"];
content.contentDescription = #"Text for facebook";
content.contentTitle = #"Results.";
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];

Trying to text from my iOS app fails with wrong number error

So I have a button in my app that people can click which is suppose to open the chat app and allow the user to send a text to the number I specify.
Here is the code:
NSString *phoneNumberStuff = [NSString stringWithFormat:#"tel:%#",self.driverPhoneNumber];
NSString *stringURL = [NSString stringWithFormat:#"sms:%#",phoneNumberStuff];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
What happens is when I click the SMS button it opens the texting app and I see in the TO: field the correct phone number to text a message to. So I type a message and hit send, but I get this response back.
"15558354439876552 Error Invalid Number. Please re-send using a valid 10 digit mobile number or valid short code. text again"
Anyone have a clue?
Your format for the url isn't correct.
You are using
sms:tel:1234567890
When you should use
sms:1234567890

How to open an url from the browser with a parameter in ios

I want to open an URL from the browser in ios. I know how to open an normal url.. but here I want to pass a parameter to the url.... This is what I used to open the url from the browser
NSURL *url = [NSURL URLWithString:#"http://www.iphonedevelopertips.com"];
[[UIApplication sharedApplication] openURL:url];
Then how can I modify this according to pass a parameter
Thanks
here i pass the country name. you can pass anything what you want.
CountryName=#"India";
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:#"http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=%#",CountryName]];
do like this pass whatever you want pass like this.

Resources