Using URL Scheme to get background runtime on another app - ios

Can I use the URL Scheme mechanism in app 1 to get a background runtime in app 2?
I mean to avoid app 2 lunching?
In the app 1 I do:
NSURL *myUrl = [NSURL URLWithString:#"myScheme://"];
if ([[UIApplication sharedApplication] canOpenURL:myUrl]) {
[[UIApplication sharedApplication] openURL:myUrl];
}
In app 2, this method:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation;
Can I avoid from lunching app 2, and get this method (or any other related method) to run in background?
Thanks in advance!

Related

Universal Links while app is not running

I am implementing Universal Links in my app. Every things works for me, except when the app is not running in the background. In that case how i can open a specific page in my app? iOS launches my app but i am not getting any callback in
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
in this function neither i am getting any url with this line
NSURL *launchURL = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
inside
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions this function.
Does anybody have an idea how i can get the url which caused to launch my application.
Thanks
You can access to your url in this way ...
NSDictionary *aux = [launchOptions objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey];
if (aux) {
NSUserActivity *activity = [aux objectForKey:#"UIApplicationLaunchOptionsUserActivityKey"];
NSString *urlString = activity.webpageURL.absoluteString;
}
But for better use you have to validate this URL and return YES if you can manage it
For example ...
if([urlString hasPrefix:#"https://myUrl.com"]) {
return YES;
}
.. after this the method
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
It will be called
When you open a Universal Link with your app
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,
id> *)options
is called with the Universal Link as a parameter and options if it is the case. Check apple docs for details.
In Swift 5 with a SceneDelegate file it will call:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { }
When your app is NOT running in background and user clicks on a universal link.
You need to implement
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation{
url= yourappurl://with some app link data
sourceApplication= //who called your application
}
For example if your app is called from facebook messenger, then you will get
sourceApplication=#"com.facebook.messenger"

iOS - How to implement Deep Linking to open App or go to itunes link using URL scheme

I have an issue with URL Scheme in plist file as "m.zameen.com"
but i type this in iPhone's safari browser not op[en but when i open using :// it opened
// In AppDelegate.m file
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
if([[url host] isEqualToString:#"page"]){
if([[url path] isEqualToString:#"/main"]){
[self.mainController setViewControllers:#[[[DLViewController alloc] init]] animated:YES];
}
else if([[url path] isEqualToString:#"/page1"]){
[self.mainController pushViewController:[[Page1ViewController alloc] init] animated:YES];
}
return YES;
}
else{
return NO;
}
}
// In DLViewController.m file
- (IBAction)page1Clicked:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"m.zameen.com://page/page1"]];
}
// In Page1ViewController.m file
- (IBAction)mainPageClicked:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"m.zameen.com://page/main"]];
}
In your project Info tab, add a new URL Type with the scheme you want to use to open the app, for example 'myAwesomeAppScheme', using your app bundle identifier 'com.myCompany.myAwesomeApp' in the identifier field and the scheme you want in the URL Schemes field:
Then in you app delegate you can check if the opened url has your scheme with something like this
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([url.scheme isEqualToString:#"myAwesomeAppScheme"]) {
...
}
}
And finally to open the app from an external app, the link has to be something like myAwesomeAppScheme://parameters/for/opening/viewcontrollers?otherParam=blahblah

Open and adding a Facebook page from ABUnknownPersonViewController

I've got this issue, I set up some contact information of a company to be displayed by a ABUnknownPersonViewController. One of the info is the Facebook page, if I click on it on the simulator it opens safari on the correct page. On the device the URL is intercepted by the FB app that doesn't open nothing but my timeline.
I'm aware that the same happens when you try to open an FB page URL inside the app using the method -openURL: and I know that this could be easily fixed by using that snippet.
NSURL *facebookURL = [NSURL URLWithString:#"fb://profile/113810631976867"];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://facebook.com/pagename"]];
}
The fact is that I've tried to intercept the URL by using that app delegate method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
(handleOpenURL: is deprecated), but it doesn't seems to be called.
Is there a way to intercept this opening?
I've found an answer, using the protocol methods of ABUnknownPresonViewcontroller is possible to intercept some events. I must be honest and say that I still didn't know how to recognize different actions, but in this way it works.
- (BOOL)unknownPersonViewController:(ABUnknownPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if (property == 46) { //46 seems to be number associated to the property facebook page
NSURL * facebookURL = [NSURL URLWithString:#"fb://profile/PAGE_ID"];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://facebook.com/PAGE_NAME"]];
}
return NO;
}
return YES;
}

Facebook iOS SDK 3.1 does not return to the app after authentication

I'm using Facebook iOS SDK 3.1 and it does not return to my app after authentication. I'm sure the bundle ID has been entered and the login and deep link has been enabled since last night. Anyone know the possible reason or has the same problem?
Thanks,
Make sure you added these two functions. Also check your product name matched your facebook app name. Use 'URL types' in plist.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
Facebook *fb = [self sharedFacebook];
return [fb handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
Facebook *fb = [self sharedFacebook];
return [fb handleOpenURL:url];
}

iOS handleOpenURL isn't called when becoming active??? iOS 5.1 (this is not a 3.2 issue)

I use a URL scheme to open my app and parse the query string from the URL in -didFinishLaunchingWithOptions:. This works great, but it doesn't parse the new string when the app becomes active. I have implemented the -handleOpenURL: and openURL methods as follows, but neither seems to be called when the app becomes active...
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if (!url)
return NO;
queryStrings = [self parseQueryString:[url query]];
return YES;
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (!url)
return NO;
queryStrings = [self parseQueryString:[url query]];
return YES;
}
Please help! Thanks!
Use:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
The method you're using is deprecated.
handleOpenURL is deprecated on iOS 5: you should be using application:openURL:sourceApplication:annotation: instead - have you got an application:openURL method in your app as well? If not, add one and see if it gets picked up.
To clarify the above accepted answer. You probably want to use this (I was confused by the accepted answer as it only includes the function you need and not what you need to include inside the function):
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
I personally came to this issue through the Ray Wenderlich tutorial. There are also some good tutorials using Parse which show how to integrate the two.
The full tutorial this leads up to and from this point can be found here: https://parse.com/tutorials/integrating-facebook-in-ios
Hopefully this helps lessen confusion around this issue :)

Resources