Wkwebview setDelegate Equivalent - ios

No visible #interface for 'WKWebView' declares the selector 'setDelegate:'
[self.webView setDelegate:self];
[self.webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:self.url]]];
if(HUD == nil){
HUD = [[MBProgressHUD alloc] initWithView:self.webView];
[self.webView addSubview:HUD];
HUD.delegate = self;
HUD.dimBackground = YES;
[HUD setColor:[UIColor darkGrayColor]];
}
[HUD show:YES];
}
No visible #interface for 'WKWebView' declares the selector 'setDelegate:'

Related

Showing toast message with MBProgressHUD in mac os

I am showing toast message using MBProgressHUD but with toast message getting some view with it Below is code is using
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window.contentView animated:YES];;
// Configure for text only and offset down
hud.mode = MBProgressHUDModeText;
hud.labelText = #"some message......";
hud.margin = 10.f;
hud.yOffset = 200.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:20];
For macOS Using MBProgressHud you can show like this
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:window.contentView];
hud.mode = MBProgressHUDModeText;
hud.labelFont = [NSFont systemFontOfSize:13.0];
hud.margin = 8.f;
hud.opacity = 0.7;
hud.yOffset = NSHeight(window.frame)/2-60;
hud.cornerRadius = 4.0;
hud.removeFromSuperViewOnHide = YES;
hud.detailsLabelText = #"some message......";
[window.contentView addSubview:hud];
[hud show:YES];
[hud hide:YES afterDelay:2.0];
Code:
- (void)showLoader:(NSString*)strTitle view:(UIView*)view
{
dispatch_async(dispatch_get_main_queue() , ^{
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view.window];
[view.window addSubview:hud];
hud.labelText = strTitle;
[hud show:YES];
});
}
Use like this:
[self showLoader:#"Loading.." view:self.view]
//JUST REPLACE YOUR CODE AND CHECK
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:appDel.window animated:YES];

when Navigate the another page Need to add activity indicator

#import "LoginVC.h"
#import "HOMEVC.h"
#import "DashboardVC.h"
#interface LoginVC ()
#end
#implementation LoginVC
UIActivityIndicatorView *spinner ;
-(IBAction)login:(id)sender{
NSString *userUpdate =[NSString stringWithFormat:#"%#",[Usernamefileld text]];
NSString *userUpdate1 =[NSString stringWithFormat:#"%#",[PasswordField text]];
NSString *baseURL = [NSString stringWithFormat:#"http://192.168.1.200:8094/YazakiService.svc/LOGIN/%#/%#",userUpdate,userUpdate1];
NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;
NSData *responseData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSMutableArray *serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
NSLog(#"got response==%#", serviceResponse);
NSDictionary *template=[serviceResponse objectAtIndex:0];
NSString *test=[template objectForKey:#"ValidState"];
// NSString *test1=[template objectForKey:#"Userid"];
NSString *helloString = #"1";
// //
// NSString *helloString1 =#"LFY430";
if ([test isEqual:helloString]) {
[NSThread detachNewThreadSelector:#selector(threadStartAnimating:) toTarget:self withObject:nil];
[self moveToView];
// UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Login Successfully" message:#"Correct Uername/Password" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
else{
UIAlertView *alert2=[[UIAlertView alloc]initWithTitle:#"Login Failed" message:#"Incorrect Uername/Password" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alert2 show];
[self alertView1:alert2 didDismissWithButtonIndex:alert2];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 225, 20, 30)];
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
spinner.color = [UIColor blackColor];
[self.view addSubview:spinner];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)moveToView{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
DashboardVC *initView = (DashboardVC*)[storyboard instantiateViewControllerWithIdentifier:#"Dashboardvc"];
[initView setModalPresentationStyle:UIModalPresentationFullScreen];
[spinner stopAnimating];
[self presentViewController:initView animated:NO completion:nil];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self moveToView];
}
- (void) alertView1:(UIAlertView *)alertView1 didDismissWithButtonIndex:(NSInteger)buttonIndex
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginVC *initView = (LoginVC*)[storyboard instantiateViewControllerWithIdentifier:#"loginvc"];
[initView setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:initView animated:NO completion:nil];
}
-(void)threadStartAnimating:(id)data
{
[spinner startAnimating];
}
#end
here by i initialse the indicator and start and stop the spinner but its not woking for me...
any one help me to solve the issues how to add the activity indicator when navigation the another view
Thanks in Advance
[self.view addSubview:spinner];
At this line you add the activity indicator to the current ViewController view.
However once you navigate to other view
DashboardVC *initView = (DashboardVC*)[storyboard instantiateViewControllerWithIdentifier:#"Dashboardvc"];
[self presentViewController:initView animated:NO completion:nil];
the current view changes to the new ViewController's view.
The activity indicator isnt present in that view and therefore you wont see your activity indicator there.
To solve, you should again add activity indicator in the second ViewController's viewDidLoad method
In Dashboard VC
- (void)viewDidLoad {
[super viewDidLoad];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 225, 20, 30)];
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
spinner.color = [UIColor blackColor];
[self.view addSubview:spinner];
}
A better solution would be to use third party progress huds which make
the loading indicator part absolutely easy like MBProgressHUD
You should add activityindicator on navigation controller so, it is remains on front when you navigate.
you should use MBProgressHud the great third party library.
Just put class in your project and import .h file in your class when you want to show activity indicator and then add HUD (activity indicator) like,
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
// in your case show hud on `self.navigationController.view`
// use main thread to show if required
and hide like,
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
// Do something...
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
});
Hope this will help :)
When you stop UIActivityIndicatorView then also hide it.
[spinner setHidesWhenStopped:YES];
EDIT:
If you are not sure about NSThread then just do like this.
if ([test isEqual:helloString]) {
//[NSThread detachNewThreadSelector:#selector(threadStartAnimating:) toTarget:self withObject:nil];
[spinner startAnimating];
[self moveToView];
}
And when you want to stop it ten
[spinner stopAnimating];
[spinner setHidesWhenStopped:YES];
instead of using indicator , use svprogresshud.Check this link https://github.com/SVProgressHUD/SVProgressHUD.
if you want animated progressbar check this link https://github.com/cemolcay/GiFHUD

Unable to show the activity indicator iOS

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];

iOS: How to put a button on the top of SKStoreProductViewController

I want to put a custom button on the top of SKStoreProductViewController. I tried it like below but it did not work. I was wondering if you could give me any advices.
SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:#selector(showShareDialog)];
storeViewController.navigationItem.rightBarButtonItem = shareButton;
storeViewController.delegate = self;
[self presentViewController:storeViewController animated:YES completion:^() {
[storeViewController loadProductWithParameters:#{SKStoreProductParameterITunesItemIdentifier:appId}
completionBlock:^(BOOL result, NSError *error) {}];
}];

MFMessageComposeViewController not working

I have a simple method that gets one argument and then sends a message. It is not working.
Code:
- (void)sendSMS:(NSString *)text {
MFMessageComposeViewController *viewController = [[MFMessageComposeViewController alloc] init];
viewController.body = text;
viewControllerM.mailComposeDelegate = self;
[self presentViewController:viewController animated:YES completion:nil];
}
What's wrong?
You need to set the delegate:
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = #"YO";
controller.recipients = [NSArray arrayWithObjects:#"5625555555", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}

Resources