Launch app from URL issue - ios

I'm trying to launch my app using URL from Safari.
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"Launched with URL");
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(#"Launched normally");
// Override point for customization after application launch.
return YES;
}
(Also tried -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
)
If the app is in the background (i.e, if I double click the home button, it's there) the app launches correctly and console shows Launched with URL.
However, if I close it completely, meaning, double clicking home button, holding the app and clicking the minus sign, when trying to launch it again via Safari, it just shows a black screen and logs nothing to console.
This happens both on the device and simulator (5.1 both)
Is there another delegate which should be called when the app is completely closed?
Thanks!

If your application is opening from Safari, this means you have implemented the URL schema correctly.
Handle the Opened URl in these application delegate events
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:
(NSString *)sourceApplication
annotation:(id)annotation
{
}
Just Make sure you have properly encoded your URL it might be the case that your URL is breaking.

Related

How to handle the url when app is launched?

How to handle the deep link in iOS objective c when the app is suspended. If the app is in the background open url delegate will be calling so can handle the url there.
In which delegate method can handle the url when the app is launched from a deep link with custom url scheme and parameters.
Url is something like myapp://params?app_id=1234
Thanks in advance.
I have implemented Firebase Dynamic Link in my project(Similar to deferred links from Facebook) and the following delegate helps to handle Universal Dynamic Links :
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
(nonnull void (^)(NSArray *_Nullable))restorationHandler {
}
NSUserActivity Object will contain "webpageURL" that you are looking for.
Further, you can look for the below discussion to solve this :
Firebase Deeplink not calling application:continueUserActivity:restorationHandler function of AppDelegate in Swift 3
I suspect your main logic expects - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options to be called.
I also suspect in your case it does not get called if the app has been killed.
The solution is simple - make sure you have both - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions and - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions and that they both return YES.
This will make iOS call - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options on app launch.

application:openUrl: is called multiple times in iOS9

For this problem, I created a new project with a single view.
I set a url scheme and added a label in the view.
And code is here.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
ViewController *vc = (ViewController *)self.window.rootViewController;
vc.textLabel.text = [NSString stringWithFormat:#"%#\n%#",vc.textLabel.text,url.absoluteString];
return YES;
}
It works fine.
But if I add some time-consuming operations at app initialize,
like this.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[NSThread sleepForTimeInterval:1];
return YES;
}
Then I found this problem through those steps:
use safari to start the app through input the url scheme
wait it jumps to the app, and press the home button immediately
tap the app icon to continue
get two lines of url on the label
UIApplication calls application:openUrl: multiple times.
I tried using this delegate, same problem.
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
You can press the home button and tap the app icon multiple times, than openUrl will be called multiple times, it depends on cost of time-consuming operations.
I tested on iOS 9.3.3 and iOS 9.3.1, got same problem.
I tried on iOS 8.1.2 and iOS 10.2 not found this problem.
Any ideas/suggestions would be highly helpful & very thankful

iOS - On clicking notification it does not redirect to respective page

In IOS,
When app is removed from background and user obtain notification,by tap on that notification it is not triggering
function
$rootScope.push.on('notification', function (data) { });
If app running in background, then by tap of notification it is triggering this function.
Is there any other way to trigger this function when app is not running in background in ios.
Don't know in ionic, but in iOS
you will have to handle this in iOS as below
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *pushInfo = launchOptions[ UIApplicationLaunchOptionsRemoteNotificationKey];
[self application:application didReceiveRemoteNotification:pushInfo];
}

custom URL scheme does not work when app is not running in background

I am calling a custom URL from safari to launch an app. It works fine if the app is running in background. But when the app is not running in background , but is already installed on the device, the app does not launch. I have implemented both of the following methods:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
but none of them is called when app is not running in background.
Also I have googled and found that we can launch the app using the following code when app is not running in background
if ( [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey] != nil ) {
NSURL *url =(NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
[self application:application handleOpenURL:url];
}
in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
But unfortunately , didFinishLaunchingWithOptions is also not triggered. Does some one has any pointers?
P.S : This problem occurs only in iPad.It works fine on iPhone.
i was facing the same problem.
Seems that our code was running too fast.
Inserting a delay to run your custom code will resolve the issue.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:#selector(yourCustomActions) userInfo:nil repeats:NO];
return YES;
}
Hope it helps
Got to your info.plist and perform the necessary changes
Add new row --> URL types
expand it
in item 0 add new row ---> URL Schemes
expand it
In Item 0 under it, add the custom url you want to use
add one row under item 0 of urlTypes --> URL identifier
provide the bundle id of your app there
eg: anubhab://stackoverflow.com/
for the above custom url you would set the URL Scheme item 0 as:
anubhab
see the image attached for detail
I have followed these link. Hope it helps. It works fine for me even if I kill the app from background.
Wayback machine version of that link: https://web.archive.org/web/20170707150909/http://chrisrisner.com/31-Days-of-iOS-Day-18-Opening-your-App-from-a-Website.

IOS5 Facebook integration - fbDidLogin is not called

I've been spending days on doing a simple Facebook post through an app. I used this tutorial and found out that fbDidLogin is not called. As I've been looking for solutions, I've found out that this is a way to make the fbDidLogin be called.
Enlighten me as to what I may be missing out.
Attached here is the essential methods for FB integration in my app delegate.
App delegate.m
#synthesize window = _window;
#synthesize wallSnapVC = _wallSnapVC;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.wallSnapVC = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:#"wallSnapViewController"];
self.window.rootViewController = self.wallSnapVC;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [[_wallSnapVC facebook] handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[_wallSnapVC facebook] handleOpenURL:url];
}

Resources