moberwasserlechner / capacitor-filesharer

Capacitor plugin to download and share files for the Web, Android and iOS! Stop the war in Ukraine!
MIT License
82 stars 20 forks source link

Not working on ipad 13.2+ #16

Closed moberwasserlechner closed 4 years ago

moberwasserlechner commented 4 years ago

The dialog is not shown any more on at least IOS 13.2.1 and 13.3.

XCode Debug output

2020-01-04 19:49:21.209085+0100 App[297:5948] [Process] kill() returned unexpected error 1
2020-01-04 19:49:21.371510+0100 App[297:5948] [Process] kill() returned unexpected error 1
2020-01-04 19:49:21.854794+0100 App[297:5948] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x28177cf00 LPLinkView:0x105209ac0.leading == UILayoutGuide:0x280d37020'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x28177d770 H:[LPLinkView:0x105209ac0]-(59)-|   (active, names: '|':_UIActivityContentTitleView:0x1053d18b0 )>",
    "<NSLayoutConstraint:0x28170f840 H:|-(0)-[_UIActivityContentTitleView:0x1053d18b0]   (active, names: '|':_UINavigationBarContentView:0x105277860 )>",
    "<NSLayoutConstraint:0x28170def0 _UIActivityContentTitleView:0x1053d18b0.trailing == _UINavigationBarContentView:0x105277860.trailing   (active)>",
    "<NSLayoutConstraint:0x28177b7f0 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x105277860.width == 6   (active)>",
    "<NSLayoutConstraint:0x28177d1d0 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x280d37020'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIActivityContentTitleView:0x1053d18b0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x28177cf00 LPLinkView:0x105209ac0.leading == UILayoutGuide:0x280d37020'UIViewLayoutMarginsGuide'.leading   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
⚡️  TO JS {}
2020-01-04 19:49:22.858654+0100 App[297:5948] [Process] kill() returned unexpected error 1
nikosdouvlis commented 4 years ago

A little update on this. I was having the same issue and after looking into it I found out that on ipads the activity view controller is presented as a popover.

It needs either a sourceView and a sourceRect or a barButtonItem so it know where it should open from.

It seems that the sourceRect is not being set for the popoverPresentationController

I don't have time to test it right now, but you can try patching the Plugin.swift with:

(around line 23)

        try dataObj.write(to: tmpUrl)            
        let capacitorView = self.bridge.viewController.view
        let activityVC = UIActivityViewController(activityItems: [tmpUrl], applicationActivities: nil)

        // on iphones the activityVC is presented modally
        // on ipads its presented as a popover
        // it needs a sourceView and a sourceRect which is a bounds (coordinates)
        // from where the controller opens. If we dont provide the sourceRect the popover opens
        // next to the view (outside) breaking the contraints
        activityVC.popoverPresentationController?.sourceView = capacitorView
        activityVC.popoverPresentationController?.sourceRect = CGRect(x: capacitorView?.center.x ?? 0, y: capacitorView?.bounds.size.height ?? 0, width: 0, height: 0)

        DispatchQueue.main.async {
            self.bridge.viewController.present(activityVC, animated: true, completion: { call.resolve() })
        }

Its not a perfect solution since this always makes the popover to appear from the same spot (bottom of the screen, on the middle) but it should be working

moberwasserlechner commented 4 years ago

@nikosdouvlis Thx for looking into it.