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
Related
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];
}
In my application, I need to make a call, So obviously my app go to background while making a call using native call feature.if the call goes long my app is getting killed by IOS itself. Now i need to restore the last view at the time of making a call. I have used Native restoration. What i did is
1. Set the restoration ID for all the views and view controllers.
2. Override the app delegate restoration methods.
My Issue is,
If my app go to background and come back to foreground, Last view is displayed using preservation and suddenly moved to main view(Default launch view). just like last view blinking while coming to fore ground.
Here is my setting:
app Delegate code :
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
-(BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
return YES;
}
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Main view settings :
Main storyboard contains the login view as a root. Please guide me to fix the restoration issue.
I managed to get rid of the blinking by making the window key and visible in application:willFinishLaunchingWithOptions:.
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
return YES;
}
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.
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.
I'm trying to implement SSO following the Tutorial:
https://developers.facebook.com/docs/mobile/ios/build/
At the end of Step 3, I'm supposed to Test my App running it on Simulator. The Run succeeded but all I see is a Blank View (screen). I'm not sure if I need to create the view called "authorization dialog" including the FB logo, buttons, etc or if it's automatically created by code I've implemented using Facebook SDK.
Also, I'm using a storyboard and wonder if that's the problem.
I think that it's because you have once signed in and now you haven't logged out so it is already authorized and hence you cannot see anything :)
Is your initial ViewController blankView ? Because the SSO only validates/autorize the session, you need to implement the UI in your ViewController.
If you implement it in Storyboard I suggest you to do most of the code in your controller file, since I was stucked there for quite long time. But make sure to put this code in the app delegate file.
#pragma mark Facebook
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [self.facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation {
return [self.facebook handleOpenURL:url];
}
Also in the delegate file you should instantiate the Facebook object before you use the in the above methods.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
viewController *controller = [[viewController alloc] init];
// Initialize Facebook
facebook = [[Facebook alloc] initWithAppId:#"Your app ID in string" andDelegate:controller];
// Override point for customization after application launch.
return YES;
}