0

I need to upload a local picture in my webview (IOS).

Apparently, it seems that Apple has some problems with that.

2016-04-06 18:47:37.337 DemoWebView[839:112324] Warning: Attempt to present on whose view is not in the window hierarchy!

(iOS 8 SDK: modal UIWebView and camera/image picker)

Despite my extensive research, I didn't find a solution to my problem.

if anyone can help me .. I would be very grateful.

class : ViewController

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button setFrame:CGRectMake(80, 150, 160, 60)];
     button.backgroundColor = [UIColor whiteColor];
    [button setTitle:@"Click Here !" forState:UIControlStateNormal];
    [self.view addSubview:button];

}

-(void) buttonClicked:(UIButton*)sender{
    ViewController2 * test = [[ViewController2 alloc]init];
    [self presentViewController:test animated:true completion:NULL];

}


@end

class : ViewController2

@interface ViewController2 : UIViewController

@end

    #import "ViewController2.h"

    @interface ViewController2 ()

    @property (strong, nonatomic) UIWebView *webView;
    @end

    @implementation ViewController2

    - (void)viewDidLoad {
      [super viewDidLoad];

     _webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
      self.view = _webView;

      [_webView loadHTMLString:@"<br /><br /><input type=\"file\" accept=\"image/*;capture=camera\">" baseURL:nil];

    }

    @end

DemoProjet :

Thks

Community
  • 1
  • 1
KvnLf
  • 1
  • 2

2 Answers2

0

You are trying to present UIWebview indirectly from first ViewController,that's reason you are getting warning message. Try This:

#import "ViewController2.h"  

@interface ViewController2 (){
    UIWebView *webView;
}
@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];

    webView = [[UIWebView alloc] init];
    [self.view addSubview:webView]  
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    webView.frame = [UIScreen mainScreen].bounds;
    [_webView loadHTMLString:@"Your_html_string" baseURL:nil];  
}
}
@end

update: I saw your question containing link and i found that you didn't override this method

-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
    if ( self.presentedViewController)
    {
        [super dismissViewControllerAnimated:flag completion:completion];
    }
}
dev_binod
  • 427
  • 2
  • 9
  • this solution returns the same error when I choose between "take picture" or "choose Existing" in the selection popup after clicked on "Chose File" in my webview – KvnLf Apr 07 '16 at 07:21
  • If your ViewController2 has navigation controller. We cannot override dismissViewControllerAnimated: method. – quang thang Sep 29 '17 at 10:43
0

It works with the override. Thanks a lot for your answer.

EDIT

I understand why it didn't work in the first time i tried.. In my main app, i have a UINavigationController class but i continued to override the dismiss method in my UIViewController class.

KvnLf
  • 1
  • 2