我有一個WKWebview加載基於Web的用戶界面,我希望用戶能夠從他們的iCloud文檔上傳文件。我已授予正確的權限,並且可以瀏覽iCloud文檔。然而,當我選擇一個文件或點擊取消按鈕,以及解除我的WKWebview的父視圖的文檔選擇器視圖也被取消。從WKWebview解僱容器視圖的iCLoud文檔選擇器
我試圖追蹤解僱路徑。我100%確定我不打電話給我的觀點解僱功能。
有沒有人有任何想法是什麼觸發我的WKWebview容器解僱,以及如何防止它?
我有一個WKWebview加載基於Web的用戶界面,我希望用戶能夠從他們的iCloud文檔上傳文件。我已授予正確的權限,並且可以瀏覽iCloud文檔。然而,當我選擇一個文件或點擊取消按鈕,以及解除我的WKWebview的父視圖的文檔選擇器視圖也被取消。從WKWebview解僱容器視圖的iCLoud文檔選擇器
我試圖追蹤解僱路徑。我100%確定我不打電話給我的觀點解僱功能。
有沒有人有任何想法是什麼觸發我的WKWebview容器解僱,以及如何防止它?
我在使用WKWebView的Objective-C和iOS11上遇到了同樣的問題,並使用此解決方法解決了這個問題。你應該能夠將其遷移到斯威夫特輕鬆:
這個視圖控制器內部的視圖控制器擁有添加此弱屬性
@property (weak, nonatomic) UIDocumentPickerViewController *_Nullable docPickerPtr;
在相同的視圖控制器內覆蓋這兩個方法UIViewController基本類的原始部分
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion
{
if ([viewControllerToPresent isKindOfClass:[UIDocumentPickerViewController class]])
{
_docPickerPtr = (UIDocumentPickerViewController*)viewControllerToPresent;
}
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
- (void)dismissViewControllerAnimated:(BOOL)flag
completion:(void (^)(void))completion
{
if (_docPickerPtr != nil && self.presentedViewController == nil)
{
NSLog(@">>>>>>>>>>>>PREVENT FROM DOING 2nd DISMISS!");
}
else
{
[super dismissViewControllerAnimated:flag completion:completion];
}
}
我們做的是:
有在UIDocumentPickerViewController
的錯誤。
1)保存對UIDocumentPickerViewController
的弱引用,內部任何視圖控制器呈現UIDocumentPickerViewController
。 (這通常最終會被UINavigationController
,所以你可能要繼承UINavigationController
來解決這個問題。)
///Due to a bug in UIDocumentPickerViewController we need to stop the UIDocumentPickerViewController from dismissing this navigation controller. Or at least provide control. This is a weak reference to a UIDocumentPickerController that this controller presents
weak var documentPicker: UIDocumentPickerViewController?
2)覆蓋在UIViewController
這兩個功能是呈現UIDocumentPickerViewController
//MARK: Overrides
override public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
if self.presentedViewController == nil && self.documentPicker != nil {
self.documentPicker = nil
}else{
super.dismiss(animated: flag, completion: completion)
}
}
public override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
if viewControllerToPresent is UIDocumentPickerViewController {
self.documentPicker = viewControllerToPresent as? UIDocumentPickerViewController
}
super.present(viewControllerToPresent, animated: flag, completion: completion)
}
現在來自UIDocumentPickerViewController
的第二個電話將不會駁回呈現UIViewController
。