Determining Ability of Device to Make Phone Call (including with Continuity) - objective-c

I have been trying to determine whether a device is able to make a phone call, including with the new iOS9 Continuity features which allow iPads to make phone calls when connected to an iPhone. Presently my code looks something like this:
NSURL *call = [NSURL URLWithString:[NSString stringWithFormat:#"tel:1111111111"]];
if([[UIApplication sharedApplication] canOpenURL:call])
{
[[UIApplication sharedApplication] openURL:call];
}
else
{
//show an alert
}
However, when I run this on an iPad (whether or not the iPad has the phone call through an iPhone enabled) the canOpenURL function always returns true. Is there any way to distinguish whether an iPad or iOS device will make a phone call as opposed to whether it theoretically could (if a phone were connected) make the call?

Related

Open settings programmatically in iOS

I am opening the device settings page from my app.When I open through iPhone X(iOS11) and iPhone 8 it goes to app settings . But when I open through iPhone 8 Plus and iPhone SE it goes to home settings page.
I need to open home settings page of iPhone like iPhone 8 Plus(open home settings page) . I am running the below code.
UIApplication *application = [UIApplication sharedApplication];
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[application openURL:settingsURL options:#{} completionHandler:^(BOOL success) {
if (success) {
NSLog(#"Opened url");
}
}];
My problem is, I created a new project and I ran this above code . Its working fine.And I can able to navigate to device home settings page in same iPhone X.
But when I run this code in my project in iPhone X it goes to app settings screen.I don't know where I missed.
Please help me if possible.
Thanks in advance.
Global Variable
UIApplicationOpenSettingsURLString
Used to create a URL that you can pass to the openURL: method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.
https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring?language=objc
This is from Apple official document. My guess is your app have its own setting page, that's why openURL function takes you to app's setting page instead of Setting home.

How do I open another application with tvOS?

Does UIApplication:openURL work?
NSString *iTunesLink = #"http://www.youtube.com/watch?v=TFFkK2SmPg4";
BOOL did = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
This does nothing.
I assume you're wanting to test a Custom URL Scheme. You will want to use canOpenURL to see if the URL can be opened first. canOpenURL returns a BOOL value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL returns YES then you would continue to open the URL with openURL.
YouTube links open the YouTube app by default on iOS devices. This behavior is not yet testable on the new Apple TV as YouTube's app is not accessible in the tvOS beta.
Here's an example of how to use canOpenURL to see if Facebook is installed on an iOS device using its Custom URL Scheme:
Obj-C:
// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/355356557838717"]];
}
else {
// FB not installed
// Do something else
}
Swift:
// Check if FB app installed on device
if UIApplication.sharedApplication().canOpenURL(NSURL(string:"fb://")!) {
UIApplication.sharedApplication().openURL(NSURL(string:"fb://profile/355356557838717")!)
}
else {
// FB not installed
// Do something else
}
I'd anticipate that applications such as Facebook, and others, will implement their Custom URL Schemes in the same manner as their iOS counterparts.

Delegates called when there is a phone call

I'm developing a music application which also works on background. I want to catch when there is a phone call on the phone so I can pause the music.
I don't want to use CTCallCenter properties as it requires me to call them time to time. Also I used the following appDelegate method:
-(void)applicationWillResignActive:(UIApplication *)application {
NSLog(#"Phone Call!");
}
It works but it is called just once and it is not only for phone calls and when I click home button and the application is on background it happens and if there is a phone call after that it keeps playing!

iOS 6 local notifications fail when the phone is locked with app open

I have an app with basic alarm functionality. In my applicationWillResignActive: method I have it setup to create notifications to set off the alarm. This works pretty great, and I believe this is the proper way to do it (let me know if you think there is a better way).
Only in the specific situation, ONLY ON iOS 6, when the application is not "quit" (the home button is never pressed) but the user merely locks the phone or the phone auto locks, the notifications don't go off.
I have traced through the code, and the notifications are indeed being created and it worked perfectly in iOS 5.
Here is my code:
- (void)applicationWillResignActive:(UIApplication *)application
{
[UIApplication sharedApplication].idleTimerDisabled = NO;
[alarm setupForBackground];
if ([alarm isRunning]) {
[alarm stop];
}
}
Here is the notification creation method:
- (void)setupForBackground
{
UILocalNotification* alarmNotification = [[UILocalNotification alloc] init];
if (alarmNotification) {
alarmNotification.fireDate = alarmDate;
alarmNotification.timeZone = [NSTimeZone defaultTimeZone];
alarmNotification.repeatInterval = 0;
alarmNotification.soundName = #"NotificationSound.aif";
[[UIApplication sharedApplication] scheduleLocalNotification:alarmNotification];
}
}
I have been searching for an answer for a while, and I could not find anything stating something about notification changes. Thanks for any help.
I have a semi-solution. Apparently if you add an AlertBody to the notification, then it works.
My belief is that this is a bug in iOS 6. As I mentioned it worked in iOS 5, the documentation makes no mention of having such a requirement, and the notification does work without the AlertBody if the application is quit (the home button is pressed).
Still curious to see if my understanding is correct and if I should file a bug report with Apple.
Thoughts anybody?

How to connect web url in iphone application development?

I am new to iphone application.I have 6 uiimages in a view.fifth image is facebook and sixth one is twiter.Under images,Iplaced two roundrectbuttons named as click5 and click6. My requirement is,when i click on those images,I have to go to login pages of facebook and twitter.how can i do this?can anyone send me sample example and explain it detai?
If you want to send the user to the website using Safari, you invoke the openURL: method in the UIApplication class, like this:
NSURL *facebookURL = [NSURL URLWithString:#"http://www.facebook.com"];
[[UIApplication sharedApplication] openURL:facebookURL];
When assigning a button to an action, you use the UIButton's addTarget:action:forControlEvents:, providing an event handler as action. Say you're setting this up in viewDidLoad, it might look like this:
- (void) viewDidLoad {
[myButton addTarget:self
action:#selector(btnClicked:)
forControlEvents:UIControlEventTouchUpInside];
}
/**
* Click/tap event handler for some buttons
*/
- (IBAction) btnClicked:(id)sender {
// Check which button was pressed.
if (sender == self.click5) {
// ...
}
else if (sender == self.click6) {
// ...
}
}
You know the very easiest way to do this? With the free 3rd party component ShareKit. It wraps the Facebook and Twitter (and several other social network) APIs to literally make it a three-line deal to post things.
I used it for the first time in the last app I built and I was SHOCKED at how easy to use it was.