Open Setting app in iOS 10.1 via custom application - ios

I am trying to open the Settings app from my own iOS app.
My code is in Objective-C.
UIApplication *app=[UIApplication sharedApplication];
NSURL *url=[NSURL URLWithString:UIApplicationOpenSettingsURLString];
NSDictionary *dict=[[NSDictionary alloc] initWithObjectsAndKeys:[[NSNumber alloc] initWithBool:YES],UIApplicationOpenURLOptionUniversalLinksOnly, nil];
[app openURL:url options:dict completionHandler:^(BOOL success) {
NSLog(#"in open Url");
}];
This open URL method is the new method given by Apple. What should I pass in the options dictionary?

As you can see in iOS SDK:
Options are specified in the section below for openURL options. An empty options dictionary will result in the same behavior as the older openURL call, aside from the fact that this is asynchronous and calls the completion handler rather than returning a result. The completion handler is called on the main queue.
So you can just send nil to get behaviour of old openURL: method.

Try this to open settings app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]

Related

can you force ios to launch safari other than any other browser or even give an option?

Is there a way to launch safari only? I know in order to send an intent and have ios to handle it we can do [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://"]];, but if user has other browser installed (i.e. chrome), there's no guarantee safari will be used.
Reason I want to use safari is that I'm trying to have safari to handle certificate authentication for me, and according to here, only system app has permission to do so
try this
//initially we need to check safari is installed or not in our device
NSURL *url = [NSURL URLWithString:#"safari://"];
UIApplication *application = [UIApplication sharedApplication];
if ([application canOpenURL:url]) {
// if success again need to validate the our calling URL.
NSURL *linkURL = [NSURL URLWithString:#"https://iostree.wordpress.com/2017/07/29/launch-safari-from-ios-app/"];
if ([application canOpenURL:linkURL]) {
if ([application respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[application openURL:linkURL options:#{}
completionHandler:^(BOOL success) {
NSLog(#"success");
}];
}
}
}else{
NSLog(#"safari is not installed");
}

Using openScheme with POST

I have an iOS app that need to switch to Safari and open a link using a POST command. Since iOS 10 we are supposed to use 'openScheme', but where do a specify http method POST?
This is where I am so far;
- (void)openScheme:(NSString *)scheme
options:(NSDictionary *)options
{
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
[application openURL:URL options:options completionHandler:^(BOOL success) {
if (success) {
NSLog(#"Opened %#",scheme);
}
}];
}
You can achieve it by adding URLSchemes.
Below is the steps.
(i) Open your info tab in targets.
(ii) At the below, you will find URL Types option.
(iii)Fill data as shown in below image.
(iv) Now, open your Safari browser in iPhone/iPad, type YourApp:// and enter. This should open your app.
Hope this helps!

Call is not going from my ios app to Skype

Hi i am new for Ios app in my project i have added the facility for user make call from ios app to skype
for this i have installed skype in my device and when i made call call from my app call not going
What I have tried so far is the following:
NSString * userNameString = #"sarithasai";
NSString* urlString = [NSString stringWithFormat:#";skype://%#?call", userNameString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
According to the Skype URI tutorial: iOS apps by MSDN your schema is wrong. You should probably use the following instead:
NSString *urlString = [NSString stringWithFormat:#"skype:%#?call", userNameString];
Note that you should check wether or not Skype is installed beforehand which is mentioned in the linked article as well.
To start a chat use the schema
skype:user?chat
To start a video call use
skype:user?call&video=true
Try this code,
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"skype:"]];
if(installed)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"skype:%#?call", userNameString]]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.com/apps/skype/skype"]];
}
for more detail follow here.

Can't use FaceTime from app

I'm writing an App where you can call a person via FaceTime. My problem is, when I click on my button for the FaceTime-call, FaceTime opens but there is always a message "animStartXXXXXXX is not available for FaceTime." (the XXXX are random numbers). If I then call the same person from the normal FaceTime-app it works.
The code for the FaceTime-call:
NSString *facetimeString = #"facetime://";
[facetimeString stringByAppendingString:contactNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:facetimeString]];
I get the contactNumber by selecting it from the Adressbook from within my App and it works fine with normal calls/SMS.
Does anyone have a solution for my problem?
I don't think PAIR is using FaceTime for video chat.
Since FaceTime API is not available to developers, you should consider using OpenTok iOS SDK.
Here is a excerpt from GitHub site:
The OpenTok iOS SDK lets you use OpenTok video sessions in apps you build for iPad, iPhone, and iPod touch devices. This means you can use OpenTok video sessions that connect iOS users with each other and with web clients.
It is official that you can use Native app URL strings for FaceTime video calls:
facetime:// 14085551234
facetime://user#example.com
Please refer to the link: https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/FacetimeLinks/FacetimeLinks.html
Though this feature is supported on all devices, you have to change the code a little bit for iOS 10.0 and above as openURL(_:) is deprecated.
https://developer.apple.com/documentation/uikit/uiapplication/1622961-openurl?language=objc
Please refer code below for the current and fallback mechanism, so this way it will not get rejected by Appstore.
-(void) callFaceTime : (NSString *) contactNumber
{
NSURL *URL = [NSURL URLWithString:[NSString
stringWithFormat:#"facetime://%#", contactNumber]];
if (#available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:URL options:#{}
completionHandler:^(BOOL success)
{
if (success){
NSLog(#"inside success");
}
else{
NSLog(#"error");
}
}];
}
else {
// Fallback on earlier versions
NSString *faceTimeUrlScheme = [#"facetime://"
stringByAppendingString:contactNumber];
NSURL *facetimeURL = [NSURL URLWithString:faceTimeUrlScheme];
// Facetime is available or not
if ([[UIApplication sharedApplication] canOpenURL:facetimeURL])
{
[[UIApplication sharedApplication] openURL:facetimeURL];
}
else
{
// Facetime not available
NSLog(#"Facetime not available");
}
}
}
in contactNumber either pass phone number or appleid.
NSString *phoneNumber = #"9999999999";
NSString *appleId = #"abc#gmail.com";
[self callFaceTime:appleId];
objective-c ios facetime

How to show Alert when UIApplication is not able to open URL?

This method opens up the url in Safari when the website string is not null and it is atleast of length 3. But when I have supplierWebsite=#"www.heritage.com", nothing happens. I know that heritage.com is not valid website and so it is not activating in UIApplication. I would like to display atleast a pop up that would tell user that website is not available. Is there any way i can show Alertview telling that website is not available.
- (IBAction)doWebOpen:(UIButton *)sender {
if (self.provider.supplierWebSite && [self.provider.supplierWebSite length] > 3) {
NSString *urlString = [self.provider supplierWebSite];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}else {
NSError *err = [NSError errorWithDomain:#"com.cantopenweb" code:509 andDescription:#"This supplier does not have a website."];
[self showErrorAlert:err];
}}
You could use canOpenURL method,
[[UIApplication sharedApplication] canOpenURL:[NSURL
URLWithString:#"your website"]];
The method returns a BOOL, so check that for YES or NO.
If YES, it CAN else NO.
Just use canOpenURL of UIApplication class, like:
if([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
else
{
//show alert
}
canOpenURL:
Returns whether an application can open a given URL resource.
- (BOOL)canOpenURL:(NSURL *)url
Parameters
url
A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which application can
handle the URL.
Return Value
NO if no application is available that will accept the URL; otherwise,
returns YES. Discussion
This method guarantees that that if openURL: is called, another
application will be launched to handle it. It does not guarantee that
the full URL is valid. Availability
Available in iOS 3.0 and later.
Declared In UIApplication.h

Resources