Multiple inheritance from classes 'UIApplication' and 'FBSDKApplicationDelegate' - swift

I'm using iOS SDK from facebook website https://developers.facebook.com/docs/ios , but when I add FBSDKApplicationDelegate into App delegate I receive an error
Multiple inheritance from classes 'UIApplication' and 'FBSDKApplicationDelegate'.
I can't use Swift SDK, because my project is on XCode 8.2.1, Swift SDK for Facebook requires 8.3

Seem like you are using FBSDKApplicationDelegate by this way or something like this
class AppDelegate: UIResponder, UIApplicationDelegate, FBSDKApplicationDelegate
Please take a look at FBSDKApplicationDelegate carefully.
Discussion:
The methods in this class are designed to mirror those in UIApplicationDelegate, and you should call them in the respective methods in your AppDelegate implementation.
It isn't used that way. Don't make AppDelegate inheritance from FBSDKApplicationDelegate. Let use FBSDKApplicationDelegate's methods inside AppDelegate's methods
You can learn how to use FBSDKApplicationDelegate by following answer in this question Integration new facebook SDK by swift
func applicationDidBecomeActive(application: UIApplication!) {
FBSDKAppEvents.activateApp()
}
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
For more detail and easy understanding, i create a demo project with Facebook iOS SDK IntegrateFBSDK. You can try it.

Related

Can method_exchangeImplementations work between objective-c and swift?

I'm trying to get a Cordova plugin to work with a Capacitor project.
Capacitor is in Swift and the plugin is in Obj-c.
The plugin runs this bit of code to swizzle itself in the app start flow.
+ (void)load {
Method original = class_getInstanceMethod(self, #selector(application:didFinishLaunchingWithOptions:));
Method swizzled = class_getInstanceMethod(self, #selector(application:swizzledDidFinishLaunchingWithOptions:));
method_exchangeImplementations(original, swizzled);
}
original (application:didFinishLaunchingWithOptions) is in the Swift AppDelegate and swizzled (application:swizzledDidFinishLaunchingWithOptions) is in the plugin's obj-c code.
This doesn't work.
When the app starts, this bit of code runs, but the result of class_getInstanceMethod for original is always nil.
The swift delegate has
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
And the obj-c plugin has
- (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
}
I've tried adding #objc and dynamic to the swift func but that didn't help.
Is there a way to make this work?

Can I expose a Swift function to React Native without using Objective-C (pure swift)?

I wonder if I can expose my func navigateToLoginWidget to React Native. So that it can be triggered from RN.
I have managed to change the Objective-C template that comes with React Native to Swift like so:
import Foundation
import IBMCloudAppID
import BMSCore
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var bridge: RCTBridge!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// initializing App ID SDK
let region = AppID.REGION_SOMEWHERE
let backendGUID = "MY_TENANT_ID_FROM_IBM"
AppID.sharedInstance.initialize(tenantId: backendGUID, region: region)
// Initializing React Native front-end with Swift instead of Obj-c template
let jsCodeLocation: URL
jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index.js", fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "MY_PROJECT_NAME", initialProperties: nil, launchOptions: launchOptions)
let rootViewController = UIViewController()
rootViewController.view = rootView
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = rootViewController
self.window?.makeKeyAndVisible()
return true
}
func application(_ application: UIApplication, open url: URL, options :[UIApplication.OpenURLOptionsKey : Any]) -> Bool {
return AppID.sharedInstance.application(application, open: url, options: options)
}
func navigateToLoginWidget(_ sender : Any) {
print("clicked")
AppID.sharedInstance.loginWidget?.launch(delegate: SigninDelegate)
}
}
I would normally have this function in another module called SigninDelegate.swift, but I have included it in the same class for explanatory purposes.
According to the official documentation:
Swift doesn't have support for macros so exposing it to React Native
requires a bit more setup but works relatively the same.
So yes, it is possible, but some setup is needed. Check the docs in the link above for the steps you need to follow to set it up.

Oauth2 URL callback Mac Swift 4

I am using OAuth 2 into my macOS swift 4 app.
I have successfully implemented the setup of the redirect URI and when the user grants permission, the redirect URI open my mac app using the URL Schemes.
However, there is information in the URL call back that I have been unable to get a method working to catch the redirect.
I've tried these methods in the App Delegate but they don't work:
func application(_ application: NSApplication,
open url: URL,
sourceApplication: String?,
annotation: Any) -> Bool {
//Extract information from URL here
}
and:
func application(_ app: NSApplication, open url: URL) -> Bool {
//Extract information from URL here
}
What is wrong with these methods?
What method should be used in Swift 4 for a Mac app to catch the call back?
Thanks in advance
Found the answer to the question:
func application(_ application: NSApplication,
open urls: [URL]) {
}
Source: https://developer.apple.com/documentation/appkit/nsapplicationdelegate/2887193-application

swift use of unresolved FbAppCall

i am following the firebase tutorial which is Authenticating Users with Facebook https://github.com/firebase/firebase-simple-login-objc/blob/master/docs/v1/providers/facebook.md
However, i tried to compile this code and it shows the error of use of unresolved identifier 'FBAppCall'
This code was provided in the tutorial.
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(application: UIApplication, openURL url: NSURL,
sourceApplication: String!, annotation: AnyObject) -> Bool {
var wasHandled = FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication)
// any app-specific handling code here
return wasHandled
}
}
I tried to delete the fb framework and "re-install" it because i thought it related to the fbsdk version. However, it still not working.
I think FBAppCall is deprecated use this instead should be fine
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

application openURL in Swift

I am having an issue with the Appdelegate method OpenURL.
I have setup my Imported UTI's and Document Type. But when opening my app from a mail attachment, the app crashes immediately when I have the method implemented.
The depreciated handleOpenURL works, but not OpenURL?
At the moment I have no code in the implementation, and am just returning true.
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject?) -> Bool {
return true
}
The crash says Thread 1: EXC_BAD_ACCESS (code-1, address-0x0)
I don't really want to have to use the deprecated method.
I have my head blow for a week with this issue.
My app keep crashing after Login Using Social Media Such as Wechat / LinkedIn.But Facebook and Google Sign in Works Fine.
I have notice my app will keep crash after confirm sign in on Wechat Apps and will enter foreground.and Getting BAD EXCESS error. I have try to remove my application open url method on AppDelegate and the app wont crash but the action for Social Media Login are not functioning. so I detect that my issue was on the specific method. after search the web I found that im using an deprecated method of ApplicationOpenUrl as reference from https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return true
} // this method is deprecated in iOS 9 https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623073-application
notice that the deprecated version are using annotation:Any which will cause issue if you had bridging to an Obj-c framework such as wechat.
So what I do was, I swap my code into a the new format
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
let application = app
return true
}
Hope this help. it will became my reference in feature also. thanks StackOverflow
This is fairly typical of a signature mismatch between the method signatures automatically generated by the Swift compiler and the actual signature. It happens when you try to pass nil from Objective-C into a Swift explicitly unwrapped optional. Change the annotation parameter to be implicitly unwrapped and you should be gtg.
Swift 5 version of Muhammad Asyraf's answer:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplication.OpenURLOptionsKey.annotation]
return true
}