Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-7240] [4.1 Regression] iOS deep link with UIApplicationDelegate.application(_:open:sourceApplication:annotation:) implemented crashes older iOS versions #49788

Closed
swift-ci opened this issue Mar 20, 2018 · 20 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software regression run-time crash Bug → crash: Swift code crashed during execution swift 4.1

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-7240
Radar rdar://problem/38675815
Original Reporter killectro (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift 4.1 Snapshot 2018-03-19 (a) (or Xcode 9.3 beta 4 Swift version)

iOS 10.3.1 (simulator or device)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.1Regression, RunTimeCrash
Assignee killectro (JIRA)
Priority Medium

md5: b84ebb317dbc0ecbabae355d825affbf

is duplicated by:

  • SR-7355 EXC_BAD_ACCESS when implementing subclass of Formatter

Issue Description:

Deep linking using a custom URL scheme into any iOS app built with a recent Swift 4.1 toolchain causes the app to crash.

https://github.com/Killectro/SwiftCrashTest

Steps:

  • Open the above project in Xcode 9.2

  • Download any recent Swift 4.1 development toolchain or the one that shipped with Xcode 9.3 beta 4

  • Switch to 4.1 toolchain

  • On an iOS 10 device (tested with 10.3.1), run application and minimize it

  • Open Safari and type in `testing1234://` to deep link into the app

  • Observe crash

  • Switch back to Xcode 9.2 Swift toolchain

  • Attempt to repro again

  • Observe no crash

This crash only occurs if you implemented the {code:none}UIApplicationDelegate.application(_:open:sourceApplication:annotation🙂

@belkadan
Copy link
Contributor

Thanks, DJ!

@swift-ci create

@jckarter
Copy link
Contributor

It looks like there's an SDK annotation problem here to begin with—the method's being invoked with a nil annotation even though the header claims the argument is _Nonnull.

@swift-ci
Copy link
Contributor Author

Comment by DJ Mitchell (JIRA)

Happy to help 👍 thanks for taking a look so quickly!

@jckarter
Copy link
Contributor

The API docs note that that method is deprecated. If you only need to target back to iOS 9.0, then as a workaround until we fix this bug, you might try implementing the replacement API instead, which doesn't appear to have this problem: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623112-application

@jckarter
Copy link
Contributor

It looks like you can also work around the problem by defining your implementation of the delegate method with the correct optionality, even if the SDK has the wrong nullability:

    // note that `annotation` has type `Any?`
    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any?) -> Bool {
        return true
    }

@swift-ci
Copy link
Contributor Author

Comment by DJ Mitchell (JIRA)

@jckarter did you verify that the method with the modified signature is actually getting called when the deep link is triggered? I know that if I just don't implement that method then the crash also goes away so it's possible that by changing the func definition it's just not getting called.

Either way your first fix will work wonderfully, we only support >= 10.0 and we just haven't had a reason to upgrade to the new method. Thanks again for the quick turnaround and all of the work y'all do!

@jckarter
Copy link
Contributor

Yeah, I checked by putting a breakpoint in the method implementation that it was still called after changing the annotation argument type to `Any?`.

@jckarter
Copy link
Contributor

This should fix the problem in the master branch: #15465

@jckarter
Copy link
Contributor

and the 4.1 branch: #15467

@jckarter
Copy link
Contributor

Merged to both branches, so this should hopefully be fixed in future snapshots.

@swift-ci
Copy link
Contributor Author

Comment by DJ Mitchell (JIRA)

Thanks for the help and the quick turnaround @jckarter!

@dduan
Copy link
Contributor

dduan commented Apr 3, 2018

I'm seeing this with Version 9.3 (9E145), on device and simulator. Stack trace is similar:

(lldb) po Thread.callStackSymbols

▿ 27 elements

  • 0 : "0 ??? 0x000000010dc98890 0x0 + 4526278800"

  • 1 : "1 Driver 0x0000000104723570 main + 0"

  • 2 : "2 Driver 0x0000000104720880 _T06Driver11AppDelegateC11applicationSbSo13UIApplicationC_10Foundation3URLV4openSSSg17sourceApplicationyp10annotationtFTo + 260"

  • 3 : "3 UIKit 0x000000018e00cacc <redacted> + 880"

  • 4 : "4 UIKit 0x000000018e00c440 <redacted> + 596"

  • 5 : "5 UIKit 0x000000018dc28e20 <redacted> + 5468"

  • 6 : "6 UIKit 0x000000018e8876d0 <redacted> + 204"

  • 7 : "7 UIKit 0x000000018dbf1268 <redacted> + 432"

  • 8 : "8 UIKit 0x000000018e66c9b8 <redacted> + 220"

  • 9 : "9 UIKit 0x000000018e7baae8 _performActionsWithDelayForTransitionContext + 112"

  • 10 : "10 UIKit 0x000000018dbf0c88 <redacted> + 248"

  • 11 : "11 UIKit 0x000000018dbf0624 <redacted> + 368"

  • 12 : "12 UIKit 0x000000018dc2e3b0 <redacted> + 468"

  • 13 : "13 FrontBoardServices 0x0000000186854f24 <redacted> + 212"

  • 14 : "14 libdispatch.dylib 0x000000010a605220 _dispatch_client_callout + 16"

  • 15 : "15 libdispatch.dylib 0x000000010a611850 _dispatch_block_invoke_direct + 232"

  • 16 : "16 FrontBoardServices 0x0000000186888878 <redacted> + 36"

  • 17 : "17 FrontBoardServices 0x000000018688851c <redacted> + 404"

  • 18 : "18 FrontBoardServices 0x0000000186888ab8 <redacted> + 56"

  • 19 : "19 CoreFoundation 0x0000000183fff404 <redacted> + 24"

  • 20 : "20 CoreFoundation 0x0000000183ffec2c <redacted> + 276"

  • 21 : "21 CoreFoundation 0x0000000183ffc79c <redacted> + 1204"

  • 22 : "22 CoreFoundation 0x0000000183f1cda8 CFRunLoopRunSpecific + 552"

  • 23 : "23 GraphicsServices 0x0000000185eff020 GSEventRunModal + 100"

  • 24 : "24 UIKit 0x000000018defd78c UIApplicationMain + 236"

  • 25 : "25 Driver 0x00000001047235bc main + 76"

  • 26 : "26 libdyld.dylib 0x00000001839adfc0 <redacted> + 4"

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2018

The fix did not make it into Xcode 9.3. :-(

@dduan
Copy link
Contributor

dduan commented Apr 3, 2018

Found the workaround. I feel you.

@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 6, 2018

Comment by Angel Betancourt (JIRA)

Hi guys, did you found some workaround I can apply? killectro (JIRA User) @dduan , This is happening to me, using xCode 9.3, iPhone 7+ iOS 11.2.6, Swift4.1, another question, why is this duplicated of SR-7355?

@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 6, 2018

Comment by DJ Mitchell (JIRA)

angel (JIRA User) in the older comments Joe pointed out a couple of different solutions to this specific issue. If it's a different manifestation of the same compiler bug (which it looks like might be the case with SR-7355?) then you might have to find another way 'round it.

@jckarter
Copy link
Contributor

jckarter commented Apr 6, 2018

angel (JIRA User) I described a workaround in https://bugs.swift.org/browse/SR-7240?focusedCommentId=33771&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-33771 . This workaround should also be in the Xcode 9.3 release notes.

@swift-ci
Copy link
Contributor Author

Comment by Mohamad (JIRA)

[4.1 Regression] iOS deep link with `UIApplicationDelegate.application(_:open:sourceApplication:annotation🙂` implemented crashes older iOS versions

@swift-ci
Copy link
Contributor Author

Comment by DJ Mitchell (JIRA)

@jckarter @belkadan I'm assuming it did but did this end up making it into production?

@belkadan
Copy link
Contributor

Yes, this shipped in Xcode 9.4.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software regression run-time crash Bug → crash: Swift code crashed during execution swift 4.1
Projects
None yet
Development

No branches or pull requests

5 participants