Unable to open a file using Open in... since Xcode 9.3 - swift

Prior to Xcode 9.3 I had no issues importing a file, now when attempting to open a file using open in the app crashes with
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
It doesn't even reach my
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let urlName = url.lastPathComponent
print("Gotten a file \(urlName)")
}
So before my app even gets the file it crashes which I dont understand
In the AppDelegate
I also created a new empty project and getting the same issue
These are the necessary document settings
The crash location

Just by luck I came across this method
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
// read in your file
}
So replaced the method above with this and it worked.

Related

application:openURL:options: not being called with renative project after triggering function from TopShelf for tvOs

I'm trying to get the actions from the TopShelf extension for tvOS to trigger the RCTLinkManager to open my app at a specific view. but for some reason not even the application:openURL:options: function is being called where i just want to print the url to check what comes in.
What I did so far:
In my appDelegate file i've added
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
print(url)
return RCTLinkingManager.application(app, open: url, options: options)
}
also i've made sure that this returns true:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
....
return true
}
I've also added the URL types with URL Scheme and URL identifier:
Am I missing something?
Just to be complete:
I'm not using ScenesDelegate, just Appdelegate.
May there be a pod issue? Here is my list for if someone knows a known culprit:
Permission-AppTrackingTransparency
FBLazyVector
FBReactNativeSpec
RCTRequired
RCTTypeSafety
React
React-Core
React-logger
React-CoreModules
React-Core/DevSupport
React-RCTAnimation
React-RCTBlob
React-RCTImage
React-RCTLinkin
React-RCTNetwork
React-RCTSetting
React-RCTText
React-Core/RCTWebSocke
RNScreens
react-native-safe-area-context
React-cxxreact
React-jsi
React-jsiexecutor
React-jsinspector
React-callinvoker
ReactCommon/turbomodule/core
Yoga
boost
DoubleConversion
fmt
glog
RCT-Folly
React-perflogger
React-runtimeexecutor

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

LinkedIn Swift session creation completion handler not being called

I'm trying to make a basic LinkedIn login for my app and obtain the user's profile url. I installed the LinkedIn SDK in my project. A couple of notes: In the info.plist, I have put the linkedin URL Scheme, the LSApplicationQueriesScheme and the ExceptionDomains attributes appropriately. In my app delegate, I have
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if LISDKCallbackHandler.shouldHandle(url) {
return LISDKCallbackHandler.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
}
So, in one of my views I am trying to have the user login with linkedin. I put this code in to do that:
LISDKSessionManager.createSession(withAuth: [LISDK_BASIC_PROFILE_PERMISSION], state: nil, showGoToAppStoreDialog: true, successBlock: { (returnState) -> Void in
print("success called!")
print(LISDKSessionManager.sharedInstance().session)
}) { (error) -> Void in
print("Error: \(error)")
}
This code will bring the user to the linkedin app, prompt them to authorize the permissions for my app, and then returns back to my app. However, the success and error blocks never get called. I put breakpoints on both of them to make sure they just weren't printing empty strings, but they are just never called. I have tried waiting several minutes, and still nothing. What am I doing wrong?
I too had this issue. Finally solved by doing this :-
In the app delegate part you need to implement this part of code
if LISDKCallbackHandler.shouldHandle(url) {
return LISDKCallbackHandler.application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
return true
}
in the following delegate method
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
}
insted of
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
It should be like this
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
if LISDKCallbackHandler.shouldHandle(url) {
return LISDKCallbackHandler.application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
return true
}
I maybe have a solution for you. Do you maybe have multiple apps on your phone that use the same Linkedin Application ID? If you do, you should just delete the other ones.

PFFacebookUtils.logInInBackgroundWithReadPermissions block returns user = nil and error = nil

I have an iOS 9 app (Xcode 7.1, Swift 2.0) with the following pods, using the latest versions at the time of this post:
pod 'Parse' (using latest version 1.12.0)
pod 'ParseFacebookUtilsV4' (using latest version 1.11.0)
I am attempting to run the following code:
let permissions = ["public_profile", "email"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) {
(user, error) in
// Both user and error are nil here
}
But I always get a nil user and a nil error. The login worked a couple months ago, but all of a sudden (I believe after a pod update), the login stopped working.
I have added all the proper plist entries as described on the Facebook developers site, and I have added all the appropriate functions in the app delegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String
return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: sourceApplication, annotation: nil)
}
func applicationDidBecomeActive(application: UIApplication) {
FBSDKAppEvents.activateApp()
}
in AppDelegate, under didFinishLaunchingWithOptions initialize Parse before initializing PFFacebookUtils. I was making the same mistake

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
}