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

HUD is not working inside extensions #122

Open
ramunasjurgilas opened this issue Nov 24, 2016 · 17 comments
Open

HUD is not working inside extensions #122

ramunasjurgilas opened this issue Nov 24, 2016 · 17 comments
Labels

Comments

@ramunasjurgilas
Copy link

When using HUD inside extension (as I am using in Share extension) it crashes.

@PGLongo
Copy link
Collaborator

PGLongo commented Nov 24, 2016

Please can you print the log and your code? Thanks

@PGLongo PGLongo added the bug label Nov 24, 2016
@domhof
Copy link

domhof commented Dec 1, 2016

@ramunasjurgilas You cannot use PKHUD in an extension. The reason is that PKHUD tries to access UIApplication.shared which is forbidden in app extensions.

There is a fork by @Fab1n you can use: https://github.com/teamoutbank/PKHUD
In the fork the HUD is view-based instead of window-based. Just use the main view of the app extension as the base-view for the HUD.
Unfortunately it is not up to date with the version of @pkluz and it has not been ported to Swift 3 yet.

@pkluz Any chance that the view-based implementation by @Fab1n gets merged into the original PKHUD? https://github.com/teamoutbank/PKHUD/pull/1

@ramunasjurgilas
Copy link
Author

@PGLongo Error happens because it uses UIApplication, but in share extensions it is not accessible/forbidden as @domhof wrote.

Error it self happens the 5th line.

internal class Window: UIWindow {
    internal let frameView: FrameView
    internal init(frameView: FrameView = FrameView()) {
        self.frameView = frameView
        super.init(frame: UIApplication.shared.delegate!.window!!.bounds) // 5th line
        commonInit()
    }
}

@domhof Thanks for comment.

@domhof
Copy link

domhof commented Dec 6, 2016

@ramunasjurgilas If you want you can use my fork of PKHUD https://github.com/domhof/PKHUD. It is based on @pkluz s fork, but updated to 4.0.0 for Swift 3 support.

@PGLongo
Copy link
Collaborator

PGLongo commented Dec 6, 2016

@domhof I've seen your fork. Any idea on how fix this problem without breaking the compatibility?

@ramunasjurgilas
Copy link
Author

@domhof Thanks for the URL. I did look into commits and looks that this one is for Swift 3.0. Is it right?

@Fab1n
Copy link

Fab1n commented Dec 6, 2016

Hey guys. Our fork is view based AND compatible with macOS. If you take the branch feature/ob-additions you will get all goodness AND Swift 3 support! As the name oft the branch tells you, we made all changes additional on top of the official pkhud master. So it should be very simple to merge

@Fab1n
Copy link

Fab1n commented Dec 6, 2016

And we hope to get this into the official master. Would be an improvement

@pkluz
Copy link
Owner

pkluz commented Dec 6, 2016 via email

@PGLongo
Copy link
Collaborator

PGLongo commented Dec 6, 2016

@Fab1n it would be great if you could make a PR.

@Fab1n
Copy link

Fab1n commented Dec 6, 2016

Here it is
#125

Hope this gets pulled in soon

@PGLongo
Copy link
Collaborator

PGLongo commented Dec 6, 2016

I can make some test this Friday.

@PGLongo
Copy link
Collaborator

PGLongo commented Dec 9, 2016

I've merge only 1 commit of that PR. Today I will check and merge others PR and then release a new pod version.

@PGLongo
Copy link
Collaborator

PGLongo commented Dec 9, 2016

Released the new version. Try update your pod to 4.1.0 and then let me know.

Thanks

@PGLongo PGLongo closed this as completed Dec 9, 2016
@tarigancana
Copy link

hi, I try to using 4.2.0 on my share extension podfile, and got the error like the attachment.
screen shot 2017-02-08 at 8 04 29 pm
is this issue is already fix on the latest version ?

@Fab1n
Copy link

Fab1n commented Feb 8, 2017

Sorry no, currently it is not possible to use that from an extension. You should propose a pullRequest or open a ticket for that. Maybe there is one already

@PGLongo
Copy link
Collaborator

PGLongo commented Feb 8, 2017

I'm looking into it but it's very difficult for me at the moment to fix this.

If you have the time you could try the following:

  1. Remove WindowRootViewController because it seems unused
  2. Add an Other Swift Flags as follow
#if PKHUD_SHARED_EXTENSION
   guard null != view else {
    //throw Exception
 } 
#else
   let view: UIView = view ?? viewToPresentOn ?? UIApplication.shared.keyWindow!
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants