2016-10-19 10 views
1

背景&短い要約にのiPadシミュレータの罰金が、私は私のアプリのためのWebページを表示するためにWkWebviewを使用していますWKWebview

を使用して画像をアップロードする際にiPadはアプリがクラッシュします。カメラや写真ライブラリから画像を選択できるようにしました。しかし、画像の選択時にアプリがクラッシュするという問題があるようです。

仕様

私は私はシミュレータ上XCodeの8から両方

を実行していますスウィフト3を使用して、シミュレータ上で、タブレット上のIOS 10.0.2上で実行されている、およびIOS 10.0ています

2016-10-19 02:15:36.150670 z4[31561:14708540] [Generic] 
Creating an image format with an unknown type is an error 
:画像

私は、次のメッセージが表示されますをアップロードしようとすると「エラー」を取得

画像は正常ですので、アップロードに使用できます。この動作は、私は奇妙だと思ったが、私はそれは私がアプリはAppDelegateにクラッシュするようで、次の

Terminating app due to uncaught exception 'NSGenericException', 
reason: 'Your application has presented a 
UIAlertController (<UIAlertController: 0x151e80350>) 
of style UIAlertControllerStyleActionSheet. 

The modalPresentationStyle of a UIAlertController 
with this style is UIModalPresentationPopover. 
You must provide location information for this 
popover through the alert controller's popoverPresentationController. 


You must provide either a sourceView and sourceRect or a barButtonItem. 
If this information is not known when you present the alert controller, 
you may provide it in the UIPopoverPresentationControllerDelegate method 
-prepareForPopoverPresentation.' 

を得る錠剤自体でIOS

上のメモリ管理に関係していることを読みました。私は彼らの推薦をどうやって行うのか分かりません。これが深刻な問題の一部であるかどうか、あるいは私が本当に簡単なものを見逃しているかどうかもわかりません。私は、次のUIAlerts

に関連している

コードは、私は、この例外を処理し、私のアプリにはないので、この問題を解決するにはどうすればよい私はUIAlertController

func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping() -> Void) { 


     let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet) 

     alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in 
      completionHandler() 
     })) 
     self.popoverPresentationController?.sourceView = self.view 
     self.popoverPresentationController?.sourceRect = self.view.bounds 
     self.present(alertController, animated: true, completion: nil) 
    } 

    func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) { 


     let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet) 

     alertController.addAction(UIAlertAction(title: "Yes", style: .default, handler: { (action) in 
      completionHandler(true) 
     })) 

     alertController.addAction(UIAlertAction(title: "No", style: .default, handler: { (action) in 
      completionHandler(false) 
     })) 
     self.popoverPresentationController?.sourceView = self.view 
     self.popoverPresentationController?.sourceRect = self.view.bounds 
     self.present(alertController, animated: true, completion: nil) 
    } 

    func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) { 


     let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .actionSheet) 

     alertController.addTextField { (textField) in 
      textField.text = defaultText 
     } 

     alertController.addAction(UIAlertAction(title: "Yes", style: .default, handler: { (action) in 
      if let text = alertController.textFields?.first?.text { 
       completionHandler(text) 
      } else { 
       completionHandler(defaultText) 
      } 

     })) 

     alertController.addAction(UIAlertAction(title: "No", style: .default, handler: { (action) in 

      completionHandler(nil) 

     })) 

     self.popoverPresentationController?.sourceView = self.view 
     self.popoverPresentationController?.sourceRect = self.view.bounds 
     self.present(alertController, animated: true, completion: nil) 
    } 

に関連している3つの機能です私にクラッシュ?必要に応じて詳細とコードを提供することができます。事前にあなたの助けをありがとう。

答えて

2

iPadで作業するには、コードを少し変更する必要があります。私はあなたのコードの欠けている行を追加しています。

self.popoverPresentationController = alertController.popoverPresentationController 
alertController.modalPresentationStyle = .Popover 

これらの2行のコードを3つの機能で追加します。

+0

self.popoverPresentationControllerは、実際にgetOnly方法である、と私はalterController.modalPresentationStyleをアンインストールし、再インストール時に= .popoverは動作しませんでした。 – applecrusher

+0

さらに検索した後、ファイルピッカーを使用していると同時にアラートを出していたので、それは問題の束を引き起こしていたという事実と関係していました – applecrusher

+0

もう一度壊れたようです。 – applecrusher

0

下記のObjective-Cコードを参考にしてください。それはあなたのために働くかもしれません。

- (void)showAlertWithTitle:(NSString *)title withMessage:(NSString *)message withStyle:(UIAlertControllerStyle) alertStyle andActions:(NSArray *)actions andSource:(UIView *)sourceView{ 

UIAlertController *alertController= [UIAlertController 
            alertControllerWithTitle:title 
            message:message 
            preferredStyle:alertStyle]; 
for (UIAlertAction *action in actions) { 
    [alertController addAction:action]; 
} 

UIWindow *alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; 
alertWindow.rootViewController = [[UIViewController alloc]init]; 
alertWindow.windowLevel = UIWindowLevelAlert + 1; 
[alertWindow makeKeyAndVisible]; 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    [alertController setModalPresentationStyle:UIModalPresentationPopover]; 
    UIPopoverPresentationController *popPresenter = [alertController 
                popoverPresentationController]; 
    popPresenter.sourceView = sourceView; 
    popPresenter.sourceRect = sourceView.bounds; 
} 
[alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil]; 

}

- (void)dismissAlertController{ 
UIWindow *topWindow = [UIApplication sharedApplication].windows.lastObject; 
[topWindow.rootViewController dismissViewControllerAnimated:YES completion: nil];} 

は、上記の方法を使用するには、ここでサンプルです。

__weak typeof(self) weakSelf = self; 
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { 
    // Cancel button tappped. 
    [weakSelf dismissAlertController]; 
}]; 
UIAlertAction *removeAction = [UIAlertAction actionWithTitle:@"Remove" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { 
    [weakSelf dismissAlertController]; 
    //Do your actions 
}]; 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
    [self showAlertWithTitle:@"Are you sure you want to remove?" withMessage:nil withStyle:UIAlertControllerStyleActionSheet andActions:@[removeAction,cancelAction]]; 
} 
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ 
    [self showAlertWithTitle:@"Are you sure you want to remove?" withMessage:nil withStyle:UIAlertControllerStyleActionSheet andActions:@[removeAction,cancelAction] andSource:sender]; 
} 
関連する問題