我目前正在做一个学校项目,我的 iphone 应用程序被拒绝了两次,我知道为什么。我的问题的解决方案虽然很困难。在这里,我有来自我的项目的 .m 文件,并且我有一个基于 Web 的应用程序。现在,如果地址栏中只有 http://,它会显示一个错误,指出找不到 url 的主机,因为它只是 http://,我的应用程序因此被拒绝。我想要它做的是当地址栏中只有 http:// 时,让它转到不同的网站。请帮忙!!另外我在 iOS 6
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
-(IBAction)press {
label.hidden = 0;
addressBar.hidden = 0;
browserPlace.hidden = 1;
button.hidden = 1;
button2.hidden = 0;
}
-(IBAction)press2
{
label.hidden = 1;
addressBar.hidden = 1;
browserPlace.hidden = 0;
button.hidden = 0;
button2.hidden = 1;
}
- (void)viewDidLoad
{
label.hidden = 1;
addressBar.hidden = 1;
browserPlace.hidden = 0;
button.hidden = 0;
button2.hidden = 1;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
addressBar.text = [defaults objectForKey:@"history"];
[self searchBarSearchButtonClicked:addressBar];
}
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
[browserPlace loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[self parseUrl:addressBar.text]]]];
}
-(NSString*) parseUrl: (NSString*) url
{
if ([url hasPrefix:@"http://"] || [url hasPrefix:@"https://"])
return url;
else
return [NSString stringWithFormat:@"http://%@", url];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:addressBar.text forKey:@"history"];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
label2.hidden = 0;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
label2.hidden = 1;
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"%@", [error description]);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
label2.hidden = 1;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[error description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:YES animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:YES];
}
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
[searchBar setShowsCancelButton:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end