How to replace - (BOOL)application: openURL: sourceApplication: annotation:(id)annotation - ios

Well I tried my best to resolve this but had absoultely no luck.
I have this paragraph that use to work properly. But need to resolve the deprecate method.
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"%#",url.scheme);
NSString *path = [[NSBundle mainBundle] pathForResource: #"Info" ofType: #"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path];
NSString *str = [NSString stringWithFormat:#"fb%#",[dict objectForKey: #"FacebookAppID"]] ;
BOOL result = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
if (result) {
return YES;
}
return [self.instagram handleOpenURL:url];
}
I see that it is now deprecated.
iOS (4.2 and later) Deprecated:Use application:openURL:options: instead. Which produces the following. But this is not called. What am I missing?
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
NSLog(#"%#",url.scheme);
NSString *path = [[NSBundle mainBundle] pathForResource: #"Info" ofType: #"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path];
NSString *str = [NSString stringWithFormat:#"fb%#",[dict objectForKey: #"FacebookAppID"]] ;
BOOL result = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
if (result) {
return YES;
}
return [self.instagram handleOpenURL:url];
}
Thank you in advance for reviewing and any help is greatly appreciated.

The method "application:openURL:sourceApplication:annotation:" is deprecated from iOS9 onwards. So basically as #user2559325 suggests , this call back will not work in devices below iOS9. Please refer the following SDK interface.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
NS_DEPRECATED_IOS(4_2, 9_0, "Please use application:openURL:options:")

Look at this post. It's is in swift but its basically the same implementation.
In objective-c it would be something like this
NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:nil];

The method you are using is available from iOS 9.0 onwards. It will not be called in devices below iOS 9.0.
Also for it to work in iOS 9+ devices. You have to add the LSApplicationQueriesSchemes key to your Info plist
LSApplicationQueriesSchemes (Array - iOS) Specifies the URL schemes
you want the app to be able to use with the canOpenURL: method of the
UIApplication class. For each URL scheme you want your app to use with
the canOpenURL: method, add it as a string in this array. Read the
canOpenURL: method description for important information about
declaring supported schemes and using that method.
To learn about the converse operation of registering the URL schemes
an app can handle, read the description of the CFBundleURLTypes key.
This key is supported in iOS 9.0 and later.

Here is the simple solution for this in Swift 3.
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
}

Related

Passing data from native to react native

My application has the following steps:
Send file with own extension to user's email
When file is opened, the app is started (after user has select it)
Now I want to use the data from the file.
But how?
I added following function to my AppDelegate.m file in Xcode.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if (url){
NSString *information = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
UIViewController *rootViewController = [UIViewController new];
//this is not the way to display this on the screen
NSLog(#"The file contained: %#",information);
}
return YES;
}
Is it possible to use this information string in react-native? What do I need to add to use it as 'this.props.information' in my react-native app?

Can I possibly get the parameter in URL Scheme when my app set to not run in background?

I am trying to open my app using URL Scheme with a parameter on it, my problem is, is it possible to get the parameter when the app is set to not run in the background.
SampleApp-info.plist
<key>UIApplicationExitsOnSuspend</key>
<true/>
AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
{
NSLog(#"url recieved: %#", url);
NSLog(#"scheme: %#", [url scheme]);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
return YES;
}
When UIApplicationExitsOnSuspend is set to true and try to open my app from Safari, it's not creating any logs but when I remove the key it is working well. I have to restart my app to load the first viewcontroller and suspending it on the background is the best way, I think...
Can anyone help me on this? or a better way so I can reload my app starting in the first viewcontroller? Newbie here.
I really appreciate any help. Thank you and regards.
UIApplicationExitsOnSuspend Settings
You have to set UIApplicationExitsOnSuspend to false. URL Scheme Callback will not work with UIApplicationExitsOnSuspend set to true. If you want to have a simular behavior like UIApplicationExitsOnSuspend set to true just add the following code
- (void)applicationDidEnterBackground:(UIApplication *)application {
[super applicationDidEnterBackground:application];
exit(0);
}
First you have to make an entry in in Info.plist
e.g. entry your URL Scheme. In this case (in the picture) the callback will be blurry:// the identifier should be normally unique
Callback Implementation
For Pre iOS 9 swift
optional func application(_ application: UIApplication,
handleOpenURL url: NSURL) -> Bool {
NSLog("URL is %#", url)
return true
}
For Pre iOS 9 objective-c
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// handler code here
NSLog(#"Url is %#, url);
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
// handler code here
NSLog(#"Url is %#, url);
return YES;
}
IOS 9 objective-c
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,
id> *)options {
NSLog(#"Url is %#", url);
return YES;
}
IOS 9 - Swift
optional func application(_ app: UIApplication,
openURL url: NSURL,
options options: [String : AnyObject]) -> Bool {
NSLog("URL is", NSURL)
return true
}
Test the callback
Just open the weburl in the example case blurry://test with the mobile safari on your Handy

change CustomViewController fields from AppDelegate

I'm new to ios(android dev)
I'm handling opening my app from url, and i got the url in current method in my AppDelegate.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"Calling Application Bundle ID: %#", sourceApplication);
NSLog(#"URL scheme:%#", [url scheme]);
NSLog(#"URL query: %#", [url query]);
return YES;
}
There are certain params in my link which i'd like to use to fill the textField of my LoginViewController.
Can i communicate with LoginViewController from AppDelegate? consider that LoginViewController already didLoad.
You can define one property let’s say strName in appDelegate.
Then you have to assign it’s value from this method
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"Calling Application Bundle ID: %#", sourceApplication);
NSLog(#"URL scheme:%#", [url scheme]);
NSLog(#"URL query: %#", [url query]);
//for example
self.strName = [url query];
return YES;
}
Now you can access this property from anywhere.
Create Instance of appDelegate In your viewController
#define AppDel ((AppDelegate *)[UIApplication sharedApplication].delegate)
Then assign as below
textfield.text = AppDel.strName;
You can communicate with your controller in several ways:
Hold instance in appDelegate and call methods.
Save your data in some sort of storage (UserDefault for ex.) and extract in in viewWillAppear or viewDidAppear methods.
Use your own observer pattern implementation or NotificationCenter

Linkedin SDK issue in ios

i am using Linkedin SDK in ios.
i am using following code to authenticate the user
[LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, LISDK_EMAILADDRESS_PERMISSION, nil]
state:nil//#"some state"
showGoToAppStoreDialog:YES
successBlock:^(NSString *returnState) {
}
errorBlock:^(NSError *error) {
}
];
by using this code , i am able to open linkedin app but unable to get callback from linkedin app to my app.
Not Getting call on
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"%s url=%#","app delegate application openURL called ", [url absoluteString]);
if ([LISDKCallbackHandler shouldHandleUrl:url]) {
return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
return YES;
}
i am using "liMY_APPID" in URL Schemes.And also try from LinkedIn iOS SDK Bundle Suffix
Please help me how i can get callback from linkedin app
Make sure if you are using iOS 9.0 or higher as base SDK since
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
is deprecated from iOS 9. Instead use
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<NSString *,
id> *)options
Use options[UIApplicationLaunchOptionsSourceApplicationKey] and options[UIApplicationLaunchOptionsAnnotationKey] for sourceApplication and annotation respectively.
Example:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
if ([LISDKCallbackHandler shouldHandleUrl:url]) {
return [LISDKCallbackHandler application:app openURL:url sourceApplication:options[UIApplicationLaunchOptionsSourceApplicationKey] annotation:options[UIApplicationLaunchOptionsAnnotationKey]];
}
return YES;
}
Your code is correct only but your problem is related to URL schemes...
Add the same URL scheme in your info.plist file what you have mentioned in "iOS URL Suffix Schemes" so that once linkedIn will call the same URL scheme, Might be you have used incorrect URL scheme in your app.
URL scheme is nothing but it is a link to open your application. If you enter your URL scheme in mobile safari i.e.
testApp://
it will open your app (If installed). Using following process you can add it in your project
right-click on your info.plist and choose Open As – Source Code:
right-click on your info.plist and select Show Raw Keys/Values, the output will look as follows:
check link for more details to add custom URL schemes
ISSUE RESOLVED
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if LISDKCallbackHandler.shouldHandle(url) {
LISDKCallbackHandler.application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
return true
}
Did you add the LIAppId property to your Info.plist?
Have you added all your bundles to LinkedIn dev's center for iOS? If not, copy your bundle id and add it to https://www.linkedin.com/developer/apps/APP_ID/mobile and do not forget to Save.

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

Resources