Open URL scheme from iOS extension - ios

I have this code that return success = NO
[self.extensionContext openURL:[NSURL URLWithString:#"URLApp://"] completionHandler:^(BOOL success) {
[self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
}];
So and I can't open containing app from my share extension when I debug it.
I've configured main target of contained app like this:
I've tested open URLApp:// from safari and it works for me.
I also used some examples provided here to understand how to open containing app using url scheme.

EDIT: Ok, just a little correction here. I got it working with placing a button over the label just like suggested above and the following code:
NSURL *url = [NSURL URLWithString:#"floblog://"];
[self.extensionContext openURL:url completionHandler:nil];
I linked it to a "Touch Up Inside" event. However, this also causes the app to launch when the user scrolls the Today view.
=======================================
I ran into the same issue. However, it seems that there is no solution for now since the release notes for the first beta of iOS 8 mention:
Known Issues: openURL does not work from an extension.
So I guess we will at least have to wait until beta 2.

I found this answer here by Julio Bailon:
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
NSString *urlString = #"URLApp://";
NSString * content = [NSString stringWithFormat : #"<head><meta http-equiv='refresh' content='0; URL=%#'></head>", urlString];
[webView loadHTMLString:content baseURL:nil];
[self.view addSubview:webView];
[webView performSelector:#selector(removeFromSuperview) withObject:nil afterDelay:2.0];

Related

In iOS how we come back to initial view after google+ sharing?

I am implementing google plus sharing successfully by using the following lines of code. But after sharing it doesn't come back to initial screen. Is there any delegate call after completing the procedure of sharing
- (void)googelSharing{
//Set bool for Handler
[self setUserDefaultForSharing:NO];
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.clientID = kClientId;
signIn.scopes = #[#"https://www.googleapis.com/auth/plus.login"];
id<GPPShareBuilder> shareBuilder = [[GPPShare sharedInstance] shareDialog];
// This line will fill out the title, description, and thumbnail from
// the URL that you are sharing and includes a link to that URL.
[shareBuilder setURLToShare:[NSURL URLWithString:#"https://www.example.com/restaurant/sf/1234567/"]];
[shareBuilder open];
}
For your information Apple will reject the app if you use
a web page in mobile Safari for creating an account or logging in, then returns the user to the app.
See this discussion.
So Google release new Google Plus SDK for sign in
Google Sign In SDK 2.0 is documented on the new dev site :
https://developers.google.com/identity/sign-in/ios/
Hope this helps
It is not possible because when u request to open the specific web page iOS automatically transfer this request to Safari . And Safari will open that web page.
One thing you can do is used UIWebView in your app and open the web page inside UIWebView and u can easily get back to pervious viewController OR web page by adding simple UIButton in currentViewController class.
Here is code
UIWebView *webView = [[UIWebView alloc]init];
NSString *urlString = #"https://www.example.com/restaurant/sf/1234567/";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
[self.view addSubview:webView];
If u are used UIWebView than refer this answer it will help you Back Button on UIWebView

iOS 8.3 Share Extension - Launching URL Schemes

since iOS 8.3 update my share extension (which calls my main app using URL Schemes) stopped working. So I found out that the UIWebView approach I had to launch my app is not working anymore. I also tried the approach Apple recommends, using NSExtensionContext, and still no results. Any thoughts about this? My code follows:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[self.view addSubview: webView];
NSString *urlString = "com.myappscheme://shareextension";
NSString * content = [NSString stringWithFormat : #"<head><meta http-equiv='refresh' content='0; URL=%#'></head>", urlString];
[webView loadHTMLString:content baseURL:nil];
and
[self.extensionContext openURL:[NSURL URLWithString:urlString] completionHandler:^(BOOL success)
{
NSLog(#"fun=%s after completion. success=%d", __func__, success);
}];
I try executing both blocks of code on the didSelectPost method from my SLComposeServiceViewController controller, which was where it worked fine previously, before updating my device to iOS 8.3
You can make a try with this code, this works but I don't know if would be accepted by Apple.
UIResponder* responder = self;
while ((responder = [responder nextResponder]) != nil) {
NSLog(#"responder = %#", responder);
if ([responder respondsToSelector:#selector(openURL:)] == YES) {
[responder performSelector:#selector(openURL:) withObject:[NSURL URLWithString:#""]];
}
}
extensionContext.openURL is meant only for Today extensions. Apple does not provide a public API to achieve this, and it seems in iOS 8.3, Apple has blocked some of the workarounds. This seems by design. If you believe this functionality is needed, please open an enhancement request / bug report.

Not able to make phone call using UIWebView

I want to make phone call using UIWebView. I tried below code which works fine in if I simply put a button and on button click execute below code. But currently on button click, I call an api and on response I execute below code.
// Make a call to given phone number
- (void)callPhoneNumber:(NSString *)phoneNumber
{
if (!self.webView)
{
webView = [[UIWebView alloc] init];
[self.view addSubview:self.webView];
self.webView.delegate = self;
}
// Remove non-digits from phone number
phoneNumber = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:#""];
// Make a call
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phoneNumber]];
[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
}
Its not even calling webview delegate methods.
What can be the reason?
Please note that I want to call using webview only, so please don't suggest to use native contact app. Using webview keeps flow within the app. When call is ended users is in app only. Using native app, if user wants to come back to my app user has to manually open the app.
To dial a phone number you have to call -[UIApplication openURL:]:
NSString *phoneNumber = #"+5512345678";
NSURL *phoneNumberURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", phoneNumber]];
[[UIApplication sharedApplication] openURL:phoneNumberURL];
Why not use this?
NSString *phoneNumberURL = [#"telprompt://" stringByAppendingString: phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumberURL]];
This takes the user back to the app automatically once the call is finished. I hope that is what you want to achieve using webview.
https://stackoverflow.com/a/12065542/569497
Are you sure self.webView has been initialized?
Change: webView = [[UIWebView alloc] init];
To: self.webView = [[UIWebView alloc] init];
and this: [NSString stringWithFormat:#"tel:phoneNumber"] don't work; try: [NSString stringWithFormat:#"tel:%#",phoneNumber]
Personally, however, I never tried to make a phone call in this way.
If you want to call via UIWebView then use this example:
+ (void)callWithString:(NSString *)phoneString
{
[self callWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",phoneString]]];
}
+ (void)callWithURL:(NSURL *)url
{
static UIWebView *webView = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
webView = [UIWebView new];
});
[webView loadRequest:[NSURLRequest requestWithURL:url]];
}

How to make a phone call AND return to the original app afterwards

If I use UIWebView to display a phone number and set the data detector type to UIDataDetectorTypePhoneNumber, then when I click on the number its possible to make a phone call.
After the phone call has ended I am returned back to my app.
However if I attempt to programatically invoke the phone app using
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:123456789"]];
or
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://123456789"]];
Then it is not possible to return back to my app after the call has finished.
Is it possible to be able to programmatically launch the phone app and then return back to my app after the call is finished, the same as if the user clicks on a number in a UIWebView?
Instead of:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://123456789"]];
use:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://123456789"]];
telprompt:// vs. tel://
This will pop up an alert view and the user will have to tap "call" but this returns to the app after the call is done.
Unfortunately, Apple does not allow this to occur, as when you do the openURL command, it will open that application, and since you cannot access anything within that application, you will have to re-enter your application yourself. You can however save your state in NSUserDefaults, and then have the user be able to go back to the same part of the app as when they left. Check here for help: iOS Human Interface Guidelines
use for instance
NSString * telNummer;
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 5.0) {
telNummer = [NSString stringWithFormat: #"telprompt://%#", person.telephoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telNummer]];
} else {
telNummer = [NSString stringWithFormat: #"tel://%#", person.telephoneNumber];
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:telNummer]]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
}
you can send local notification 2-3 seconds after the dial app is visible to the user.
it's not perfect, but clicking on the local notification is and getting back to the original app, its easier the double click on the home button and switch app.
NSURL *url = [NSURL URLWithString:#"telprompt://your phone number"];
[[UIApplication sharedApplication] openURL:url];
This might work?
UIWebView webView = [[UIWebView alloc] init];
NSURL *url = [NSURL URLWithString:#"tel:123456789"];
[webView loadRequest:[NSURLRequest requestWithURL:url]];

IBAction Open Local HTML File

I've got a view based application that one is at last just a single WebView ... with a Tabbar with some Icons.
So i need to add a small icon for go back to the localHTML File home.html.
Maybe could someone give me some informations how to handle it without change the view to a new one?
Here is how my other IBActions looks like
- (IBAction)news_button:(id)sender; {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
}
Other option could be open a Website but not in safari ... like it does at the moment.
Thanks for sharing! :)
With the line above you are opening it in Safari right now.
You can get path to the local file if it is in main bundle catalog with
NSString *filePath = [[NSString stringWithFormat:#"%#/%#", [[NSBundle mainBundle] resourcePath], #"home.html"] retain];
So why not use
[yourWebView loadRequest:[NSURLRequest initWithURL:[NSUrl initWithString:filePath]]];

Resources