How to handle the url when app is launched? - ios

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.

Related

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

How to receive message in wechat itegrated in ios?

I have integrate wechat sdk in iphone app. I can send a message with using SendMessageToWXReq class. But How i should receive the message within the my app.How GetMessageFromWXReq and ShowMessageFromWXReq works? Please provide me sample code.
onResp not called.
AppDelegate.m
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [WXApi handleOpenURL:url delegate:self];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [WXApi handleOpenURL:url delegate:self];
}
Here,if you set delegate to self ,you will get onResp called in AppDelegate.m
If you set delegate to some other viewController instance, you will get onResp called in viewController.m
If this helps you, please let me know.

PFLogInViewController/Facebook not working

Using a PFLogInViewController subclass in my app to allow users to login with Facebook, I have an issue.
While it works perfectly in some cases; in other cases it doesn’t.
After I give permissions to the user the “Loading…” spinning wheel comes up and stays there for ever.
And some times it works but the waiting time (with the spinning wheel) is a bit long.
Though I now have quite a bit of experience with Parse.com, this is the first time I try to integrate Facebook login, therefore I may well be doing something the wrong way.
Here is some of the code I use related to this:
In the AppDelegate.m I do:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
……
[PFFacebookUtils initializeFacebook];
……
return YES;
}
and:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL fbAppCallStatus = [FBAppCall handleOpenURL: url
sourceApplication: sourceApplication
withSession: [PFFacebookUtils session]];
return fbAppCallStatus;
}
In the CustomLogInViewController.m I do:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if ([PFUser currentUser]) [self quitView];
}
Let me know if there seem to be an obvious mistake here.
Thanks for any tip.

Launch app from URL issue

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.

Is it possible to receive URL data without adding callbacks in the UIApplicationDelegate?

I'm writing a shared manager class. It knows to start and stop some services by listening for the UIApplicationDidBecomeActiveNotification and similar. It's also supposed to do is to handle a certain set of URLs. At the moment, I'm getting it to do that by adding code to the UIApplicationDelegate in each of our apps like so:
#pragma mark - URL support
// Pre 4.2 support
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [[SGBMyManager sharedManager] handleOpenURL:url];
}
// For 4.2+ support
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[SGBMyManager sharedManager] handleOpenURL:url];
}
That works, but it's not very DRY. I'd like to only have to code this once, in my shared manager class. Is there a UIApplicationDidHandleOpenURL notification or similar that I could listen for?

Resources