Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 853
JetSet Avatar asked Feb 11 '16 23:02

JetSet


3 Answers

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:")

like image 138
arango_86 Avatar answered Sep 28 '22 00:09

arango_86


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];
like image 25
quant24 Avatar answered Sep 28 '22 01:09

quant24


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.

like image 28
amiladiman Avatar answered Sep 28 '22 01:09

amiladiman