When I'm loading a HTML page that contains ModalDialog in WebView,no popup window is opened at all.That same HTML page works without issue in Safari.So anyone can solve it?
Here is the code:
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request{
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask backing:NSBackingStoreBuffered defer:YES];
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
WebView *webView = [[WebView alloc] init];
[webView setFrameLoadDelegate:self];
window.contentView = webView;
[webView.mainFrame loadRequest:request];
[window makeKeyAndOrderFront:webView];
return webView;
}
- (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request{
return [self webView:sender createWebViewWithRequest:request];
}
- (void)webViewRunModal:(WebView *)sender{
[sender.window makeKeyAndOrderFront:sender];
}
- (void)webViewShow:(WebView *)sender{
[sender.window makeKeyAndOrderFront:sender];
}
- (void)webViewClose:(WebView *)sender{
[sender.window close];
}
#pragma -mark -WebView Delegate
- (WebView *)webView:(WebView *)sender createWebViewWithRequest: (NSURLRequest *)request{
NSUInteger windowStyleMask = NSClosableWindowMask|NSMiniaturizableWindowMask|NSTitledWindowMask;
_webWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 400, 300) styleMask:windowStyleMask backing:NSBackingStoreNonretained defer:YES];
[_webWindow setReleasedWhenClosed:NO];
WebView* newWebView = [[WebView alloc] initWithFrame:[_webWindow contentRectForFrameRect:_webWindow.frame]];
[newWebView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[[newWebView mainFrame] loadRequest:request];
[_webWindow setContentView:newWebView];
[_webWindow center];
[_webWindow makeKeyAndOrderFront:nil];
return newWebView;
}
- (WebView *)webView:(WebView *)sender createWebViewModalDialogWithRequest:(NSURLRequest *)request{
return [self webView:sender createWebViewWithRequest:request];
}
- (void)webViewRunModal:(WebView *)sender{
[sender.window makeKeyAndOrderFront:self];
}
- (void)webViewShow:(WebView *)sender{
[sender.window makeKeyAndOrderFront:self];
}
- (void)webViewClose:(WebView *)sender{
[sender.window close];
}
Related
My cordova library was old and had to update it because of iOS11. I have updated it to latest version 4.4.0. CDVViewController is totally different now which enables webviewEngine that takes UIWebview or WKWebview. How do I initiate Cordova webview in my native app. Previously, I loaded it like this -
- (void) viewDidLoad {
[super viewDidLoad];
CDVViewController *viewController = [CDVViewController new];
viewController.wwwFolderName = #"www";
viewController.startPage = #"blank.html";
viewController.view.frame = self.webView.frame;
[self.webView removeFromSuperview];
self.webView = nil;
[self.view addSubview:viewController.view];
self.webView = viewController.webView;
viewController.webView.delegate = self;
self.cordovaWebViewController = viewController;
self.webView.scalesPageToFit = YES;
if (self.url)
[self.webView loadRequest: [NSURLRequest requestWithURL: self.url]];
}
And used webview delegates as
#pragma mark Webview Delegate
- (void) webViewDidStartLoad: (UIWebView *) webViewLocal {
[self.spinner startAnimating];
[self.cordovaWebViewController webViewDidStartLoad:webViewLocal];
}
- (void) webViewDidFinishLoad: (UIWebView *) webViewLocal {
[self.spinner stopAnimating];
[self.cordovaWebViewController webViewDidFinishLoad:webViewLocal];
}
- (void) webView: (UIWebView *) webView didFailLoadWithError: (NSError *) error {
[self.spinner stopAnimating];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if ([request.URL.absoluteString hasSuffix: #"link_restart_movie_file"]) {
[self loadItem];
return NO;
}
[self.webView loadRequest: request];
return NO;
}
[self.cordovaWebViewController webView:self.webView shouldStartLoadWithRequest:request navigationType:navigationType];
return YES;
}
How do I use WebviewEngine to load in my viewcontroller? Is there any tutorial, that explains the usage of CDVViewController? Please help! Thanks!
I wanna change UIColor of UIWebBrowserView in web view in iOS8 Objective C.
Please help me.
Thank you.
plz use this code
UIWebView * webView_article = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 200, 400)];
webView_article.backgroundColor =yourClolor;
webView_article.delegate=self;
webView_article.scrollView.bounces = NO;
webView_article.scrollView.showsVerticalScrollIndicator = NO;
webView_article.scrollView.delaysContentTouches = NO;
webView_article.scrollView.delegate = self;
[webView_article setTag:11];
[webView_article setOpaque:NO];
you have to set setOpaque to No
UIWebView *web = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
web.backgroundColor = [UIColor colorWithRed:32.0/255.0 green:32.0/255.0 blue:32.0/255.0 alpha:0.5];
web.delegate=self;
web.scrollView.bounces = NO;
web.scrollView.showsVerticalScrollIndicator = NO;
web.scrollView.delaysContentTouches = NO;
web.scrollView.delegate = self;
[web setOpaque:NO];
pragma -web view method
-(void)webViewDidStartLoad:(UIWebView *)webView{
[SVProgressHUD showWithStatus:#"Loading..." ];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
NSLog(#"start ...");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[SVProgressHUD dismiss];
NSLog(#"finish");
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[SVProgressHUD dismiss];
NSLog(#"Error for WEBVIEW: %#", [error description]);
}
I can't get to display the activity spinner on UIWebView
Need to show UIActivityIndicatorView while the page is being loaded.
UIActivityIndicatorView is declared but it's never shown on the UIWebView
Please assist.
The code is as follows :
#import <QuartzCore/QuartzCore.h>
#import "MyScreen"
#import "Reachability.h"
#interface MyScreen ()
#end
#implementation MyScreen
{;
UIView *loadingView;
}
#synthesize gotoMainMenu;
- (void)viewDidLoad {
[super viewDidLoad];
loadingView = [[UIView alloc]initWithFrame:CGRectMake(100, 400, 80, 80)];
loadingView.backgroundColor = [UIColor colorWithWhite:0. alpha:0.6];
loadingView.layer.cornerRadius = 5;
UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center = CGPointMake(loadingView.frame.size.width / 2.0, 35);
[activityView startAnimating];
activityView.tag = 100;
[loadingView addSubview:activityView];
UILabel* lblLoading = [[UILabel alloc]initWithFrame:CGRectMake(0, 48, 80, 30)];
lblLoading.text = #"Loading...";
lblLoading.textColor = [UIColor whiteColor];
lblLoading.font = [UIFont fontWithName:lblLoading.font.fontName size:15];
lblLoading.textAlignment = NSTextAlignmentCenter;
[loadingView addSubview:lblLoading];
[self.view addSubview:loadingView];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:true];
self.navigationController.navigationBar.hidden=false;
Reachability *reach = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reach currentReachabilityStatus];
if (netStatus != NotReachable)
{
NSLog(#"Network is Available");
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Network Error" message:#"Please check internet connectivity!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil , nil];
[alertView show];
[self.navigationController popViewControllerAnimated:YES];
}
}
-(id) init
{
if([super init])
{
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, -64.00, self.view.frame.size.width, self.view.frame.size.height+64.0)];
webView.scalesPageToFit = YES;
webView.userInteractionEnabled = YES;
url = [[NSURL alloc] initWithString:#"http://theURL/"];
req = [[NSURLRequest alloc] initWithURL:url];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:5.0];
[webView loadRequest:theRequest];
[webView loadRequest:req];
[self.view addSubview:webView];
}
return self;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[loadingView setHidden:YES];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[loadingView setHidden:NO];
}
#end
You should not use "self.view" in your init function. When you use it, the view is loaded and viewDidLoad will be invoked before you add webView. So you webView is added after your loading view.
Just try to move this line:
[self.view addSubview:webView];
After:
[self.view addSubview:loadingView];
Hi in my application I'm playing the video using URL. I'm passing the video URL form my server now the problem its taking to much time to play the video. So i want to show progress bar until its load the video .
So i have used the MBProgressHUD for progress bar its showing the progress bar but the video is not playing please tell where I'm doing wrong.
My code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * currentVideo = [videoarray1 objectAtIndex:indexPath.row];
NSString *strurl=[self urlencode:currentVideo];
NSURL *url=[NSURL URLWithString:strurl];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
NSURLConnection *con=[NSURLConnection connectionWithRequest:req delegate:self];
if (con) {
datas=[[NSMutableData alloc]init];
}
spinner = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
spinner.mode = MBProgressHUDModeCustomView;
[spinner setLabelText:#"Loading file....."];
[spinner setLabelFont:[UIFont systemFontOfSize:15]];
[spinner show:YES];
}
-(NSString *)urlencode:(NSString *)str
{
NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)#"", kCFStringEncodingUTF8));
return encodeString;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(#"%lld",[response expectedContentLength]);
self.length = [response expectedContentLength];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data1{
[datas appendData:data1];
float progress = (float)[datas length]/(float)self.length;
NSLog(#"%f",progress);
float check=progress*100;
if (check==100) {
[spinner hide:YES];
[spinner removeFromSuperViewOnHide];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSData *data = datas;
NSLog(#"%#",data);
NSString* myurl;
myurl = [[NSString alloc] initWithData:datas encoding:NSASCIIStringEncoding];
NSLog(#"%#",myurl);
_movieplayer = [[MPMoviePlayerController alloc]initWithContentURL: [NSURL URLWithString:myurl]];
[[_movieplayer view] setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview: [_movieplayer view]];
[_movieplayer setShouldAutoplay:YES];
[_movieplayer prepareToPlay];
[_movieplayer play];
}
I have used the above code its not playing the video please tell where I'm doing wrong in the above code how to achieve this one.
Thanks.
1.create new view control
2.pass your videoarray1 value to nextvieww control i mean your video url
3.add following code nextview control
- (void)viewDidLoad
{
[super viewDidLoad];
self.indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
self.indicator.center = self.view.center;
[self.view addSubview:self.indicator];
[self.indicator startAnimating];
_movieplayer = [[MPMoviePlayerController alloc]initWithContentURL: [NSURL URLWithString:[self urlencode:self.strPlayUrl]]];
[[_movieplayer view] setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview: [_movieplayer view]];
[_movieplayer setShouldAutoplay:YES];
[_movieplayer prepareToPlay];
//this is the line we need to do
[self.view insertSubview:self.movieplayer.view belowSubview:self.indicator];
[self.movieplayer play];
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(#"VIEW DID LOAD");
// Register to receive a notification that the movie is now in memory and ready to play
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieLoadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
}
-(void)movieLoadStateDidChange:(id)sender
{
NSLog(#"STATE CHANGED");
if(MPMovieLoadStatePlaythroughOK ) {
NSLog(#"State is Playable OK");
NSLog(#"Enough data has been buffered for playback to continue uninterrupted..");
self.indicator.hidden = YES;
[ self.indicator stopAnimating];
}
}
-(NSString *)urlencode:(NSString *)str
{
NSString *encodeString=(NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)str, NULL, (CFStringRef)#"", kCFStringEncodingUTF8));
return encodeString;
}
I want to open links of uiwebview in to the safari browser my code is working perfectly if I implement shouldStartLoadWithRequest method in viewController but when I implement shouldStartLoadWithRequest in same class and set UIWebView's delegate to self it doesn't work it get halt in between and shows assembly level code with error EXC_BAD_ACCESS(code=2, address=0x9) my files are as follows
//content of ShowView.h file
#import <UIKit/UIKit.h>
#interface ShowView : UIView <UIWebViewDelegate> {
}
- (void) showViewFunction;
#property (nonatomic, assign) UIViewController *mainViewContObj;
#end
//content of ShowView.m file is :
#import "ShowView.h"
#implementation ShowView
- (void) showViewFunction {
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 150)];
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[aWebView setDelegate:self];
NSString *urlAddress = #"http://localhost/test/index.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
aWebView.delegate = self;
[aWebView loadRequest:requestObj];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[[[self mainViewContObj] view] addSubview:aWebView];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"In shouldStartLoadWithRequest method");
if ([[[request URL] absoluteString] isEqual:#"http://localhost/test/index.php"])
return YES;
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
#end
// Content of ViewController.h
#import "ViewController.h"
#import "ShowView.h"
#interface mnetViewController ()
#end
#implementation mnetViewController
- (void)viewDidLoad {
[super viewDidLoad];
MNETMobAd *bannerObj = [[MNETMobAd alloc] init];
bannerObj.mainViewContObj = self;
[bannerObj showAd];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Some times html page shows but when I click on link it opens in same UIWebview window, and not even going into the shouldStartLoadWithRequest method, am I doing anything wrong?
Your code isn't clear, might need more info's, but from what i see, the ShowView class is never instanciated, so it shouldn't even show.
you should make something like this i guess :
//mnetViewController.m
#import "mnetViewController.h"
#import "ShowView.h"
#interface mnetViewController ()
#end
#implementation mnetViewController
- (void)viewDidLoad {
[super viewDidLoad];
ShowView* theShowView = [[ShowView alloc] initWithFrame:CGRectMake(insert the frame you want your webview to have)];
theShowView.autoresizesSubviews = YES;
[self.view addSubview:theShowView];
[theShowView release];
MNETMobAd *bannerObj = [[MNETMobAd alloc] init];
bannerObj.mainViewContObj = self;
[bannerObj showAd];
}
now for the ShowView class, try something like this :
//ShowView.h
#import <UIKit/UIKit.h>
#interface ShowView : UIView <UIWebViewDelegate> {
}
#end
//ShowView.m
#import "ShowView.h"
#implementation ShowView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
aWebView.scalesPageToFit = YES;
[aWebView setDelegate:self];
[self addSubview:aWebView];
NSString *urlAddress = #"http://localhost/test/index.php";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
[aWebView release];
}
return self;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"In shouldStartLoadWithRequest method for URL : %#",[request [URL absolutString]]);
if ([[[request URL] absoluteString] isEqual:#"http://localhost/test/index.php"])
return YES;
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
This should work, i didn't try it, i'll comeback tomorrow to try it if necessary.