Handling different URL Schemes in iOS (Facebook and Instagram)

前端 未结 4 1712
陌清茗
陌清茗 2021-01-05 14:21

I am not even sure how to define the problem but here it goes.

I have an application that uses Facebook SDK for user login. I followed the Facebook authorization tut

相关标签:
4条回答
  • 2021-01-05 14:43

    Swift :-

    Example for use both Google+ and Facebook in swift app, both of them require the OpenURL method in the appDelegate.

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?,
        annotation: AnyObject?) -> Bool {
    
       println("URL : \(url)")
       if(url.scheme!.isEqual("fb1627825840806667")) {
            println("Facebook url scheme")
    
        return FBSDKApplicationDelegate.sharedInstance().application(
                application,
                openURL: url,
                sourceApplication: sourceApplication,
                annotation: annotation)
    
       } else {
    
            println("Google+ url scheme")
    
           return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
    
       }
    }
    
    0 讨论(0)
  • 2021-01-05 14:52

    For Swift 2.0

    //MARK: FACEBOOK , GOOGLE CALLBACK URL METHOD
        //google-Firebase signin - IOS 8
        func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
        {
            let googleDidHandle = GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation)
    
            let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
    
            return facebookDidHandle || googleDidHandle
        }
    
        //google-Firebase signin - IOS 9
        @available(iOS 9.0, *)
        func application(application: UIApplication,
                         openURL url: NSURL, options: [String: AnyObject]) -> Bool {
    
            let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
    
            let googleDidHandle = GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
    
            return facebookDidHandle || googleDidHandle
        }
    
    0 讨论(0)
  • 2021-01-05 14:57

    I think I found

    [url scheme] gives those specific URL schemes

    Xcode - multiple URL Schemes

    0 讨论(0)
  • 2021-01-05 15:05
        - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
        {
            NSLog(@"url: %@", [url scheme]);
            
            BOOL callBack;
            // Facebook Call back checking.
            if ([[url scheme] isEqualToString:@"facebook_url_schema"])
            {
                callBack = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
            }
            // Instagram call back checking.
            else if ([[url scheme] isEqualToString:@"instagram_url_schema"])
            {
                callBack = [self.instagram handleOpenURL:url];
            }
            return callBack;
        }
    

    0 讨论(0)
提交回复
热议问题