How know when app open a URL? - ios

I'm working on an iOS app and looking to see if it is possible to know when a user opens a URL (for example, user press a button and executes code like below)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://1234567890"]]
telprompt: show an alert when it's called. But I want a way to detect if user press Ok button or Cancel button. I need execute some code in -(void)applicationDidEnterBackground:(UIApplication *)application depending which button was pressed. Any idea?

You could subclass UIApplication and over-ride openURL:
This will give you control and have you decide what to do.
Make sure to call super implementation though if you want to open the URL
EDIT
Here is an example
How to subclass UIApplication?

Related

Call action when home buttom pressed iOS

Is there any way to call action on home button ?
I need something like "are you sure to quit app" and wait for yes or no.
I don't need any code or so. I just need to make sure it is possible.
Thanks
In short, no. you can't block the home button action, neither the user is expecting this to happen.
If you have to perform any kind of saving, you can do it in the application delegate object in the method applicationDidEnterBackground:
Apple documentation here
As far as I know, Apple does not allow you to do this, as it would make the overall user experience of iOS horrible. Can you imagine if every developer added this functionality to their app?
You could attempt to implement applicationDidEnterBackground, then set up a local notification that instantly notifies the user with an alert, with a button that opens the app and one that does nothing. But you cannot intercept the home button press like you would with shouldPerformSegueWithIdentifier

Directly launch phoneNumber dialog on iPad

If I use the UIDataDetectorTypePhoneNumber on a UITextView, and click a phone number on a device that has no phone (e.g. iPad), I get a Send Message / Add to Contacts / Copy popover. Is there some way to bring up that dialog directly in code or would I have to reimplement?
I did try [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:5555555"]]; but that does not bring up the dialog.
There are some subtle differences between how detected links and buttons behave and my client wants a clickable phone number that behaves like a button.
I did some method swizzling to see where this popover comes from, and it looks like it is generated before the openURL: method in UIApplication.
Digging further, it looks like the popover comes from some private objects in UITextView.
I think you'll have to reimplement.
Did you try it with some forward slashes?
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://5555555"]];
Possibly related to this.
Use telprompt://5555555 instead of tel:5555555

NewsStand, Show the push notification alert view when I want?

I know this has been asked: How to show "Would like to send you Push Notifications" Alert View again? ... But My question is kind of different. My question is that is it possible to prompt this when ever I want programmatically (not for debugging but for real). Probably not because this is an alert triggered by the operating system, but is there a way to "undo" if a user clicked "don't allow". My app has a tutorial I want to pop this message when the user finishes the tutorial. Should I just register for push notifications after the tutorial?. Or what the user has to "allow" on the settings menu so I can add it to the tutorial. Thanks
To trigger popup you provide on image you should call
[[UIApplicaton sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeNewsstandContentAvailability]
This is possible to do in any place in app.
To check available permissions use:
UIRemoteNotificationType* enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

Do action upon exit of ios app

How can I assign actions on iOS when a user presses the home button (exit)? I want this for an app where uses user a login feature and I want, upon exit, the user to log out. I dont want to use a button for this.
Use the method,
- (void)applicationDidEnterBackground:(UIApplication *)application
In your application's delegate.
You can't exit an application programmatically, you can use exit(1), however it's not a good practice, chances are there for your apps to get rejected from Apple.
applicationDidEnterBackground will be called for home button press. Try to handle everything here.
Write your actions in appDelegate's "applicationDidEnterBackground" method.

what is the function that is called when the app is appearing?

Imagine the app is running and you press the iphone button (the phone button) and you exit the app. then you tap on the app again to enter the app. My problem is that when ever the user does this I want the viewWillAppear or viewDidAppear functions to be called, but unfortunately none of these functions gets called.
I want to know if these function won't get called, then what is the function that is called when the app is appearing again?
How about - (void)applicationDidBecomeActive:(UIApplication *)application in your UIApplicationDelegate?
Look at UIApplicationDelegate. -applicationDidBecomeActive: is what you are looking for.
You can also register for notifications in your classes (UIApplicationDidBecomeActiveNotification). This may be simpler to implement than having your app delegate handle everything since you can have, for example, each view controller manage itself.
(Use NSNotificationCenter's -addObserver:selector:name:object: to register, don't forget to unregister during object cleanup, typically in -dealloc.)

Resources