candostdagdeviren / CDAlertView

Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift
https://candostdagdeviren.github.io/CDAlertView/
MIT License
1.14k stars 86 forks source link

Use without Shared Window #10

Closed indivisable closed 7 years ago

indivisable commented 7 years ago

What is the best way to implement this without using the shared window code?

UIApplication.shared.keyWindow?.addSubview(self)

indivisable commented 7 years ago

Ended up passing through show function:

public func show(target:UIView, completion:((CDAlertView) -> Swift.Void)? = nil) {
 target.addSubview(self)
self.alignToParent(with: 0)
...

Then: alert.show(target: self.nav1.view)

edasque commented 7 years ago

@candostdagdeviren is that a Swift 3 / iOS 10 issue? Should it be updated?

indivisable commented 7 years ago

No it is a general issue when using the library in an Extension (for example iMessage extension) where UIApplication is not available. I have seen this fixed in other libraries by using a macro to check if compiling an app or extension.

http://stackoverflow.com/questions/29605094/detect-whether-run-target-is-app-extension-or-ios-app

candostdagdeviren commented 7 years ago

I'll try to create a new version with more customizable for custom view use.

I was thinking, if it is going to be expandable and can be dismissed with dragging, I should add this to the window.

I'll try to create a new method to use in custom views. (It won't be a breaking change)

Lastly, if you want to jump in and make a contribution, open a PR. It would be awesome.

edasque commented 7 years ago

Duh, @indivisable you're totally right. Good point.