解析推送JSON IOS webview

我有一个ios webview应用程序,我试图将链接推送到文章。 我为了我的生活无法弄清楚如何去做。 每个通知只是打开主页。 有什么帮助吗? 我是100%新人,所以如果你可以请我解释给我像我这个白痴。

导入“ViewController.h”

@interface ViewController()

///插页式广告。

@结束

@implementation ViewController {}

  • (void)viewDidLoad {[super viewDidLoad]; //在加载视图之后,通常从笔尖执行任何其他设置。

    if([useragent isEqual:@“”]){} else {NSDictionary * customuseragent = [NSDictionary dictionaryWithObjectsAndKeys:useragent,@“UserAgent”,nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:customuseragent]; }

    //在iOS 6上ADBannerView引入了一个新的初始化程序,在可用时使用它。 [UIApplication sharedApplication] .statusBarStyle = UIStatusBarStyleDefault;

    CGRect phonecheck = [[UIScreen mainScreen]界限]; double statusbar = 20; double height = phonecheck.size.height = phonecheck.size.height-statusbar; _webView.frame = CGRectMake(0,20,phonecheck.size.width,height); _loadingSign.center = CGPointMake((phonecheck.size.width / 2),(phonecheck.size.height / 2));

    if(phonecheck.size.height == 667-statusbar){_offline.frame = CGRectMake(103,228,170,170); _text1.frame = CGRectMake(40,400,295,50); _text2.frame = CGRectMake(25,435,326,50); _tryButton.frame = CGRectMake(110,520,150,20); } if(phonecheck.size.height == 736-statusbar){_offline.frame = CGRectMake(123,205,170,170); _text1.frame = CGRectMake(60,346,295,50); _text2.frame = CGRectMake(44,374,326,50); _tryButton.frame = CGRectMake(132,453,150,20); } [UIApplication sharedApplication] .applicationIconBadgeNumber = 0; NSURL * url = [NSURL URLWithString:webviewurl]; _webView.delegate = self; 如果([preventoverscroll isEqual:@“true”]){_webView.scrollView.bounces = NO; } if([deletechache isEqual:@“true”]){[[NSURLCache sharedURLCache] removeAllCachedResponses]; } _webView.scalesPageToFit = YES; [_webView.scrollView setBouncesZoom:NO]; [_webView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)]; _offline.hidden = true; [_loadingSign stopAnimating]; _loadingSign.hidden = true; [_tryButton setTitle:buttontext forState:UIControlStateNormal]; [_tryButton setTitle:buttontext forState:UIControlStateSelected]; _text1.text = screen1; _text2.text = screen2; _text1.hidden = true; _text2.hidden = true; _tryButton.hidden = true; NSString * onlinecheck = [url absoluteString]; if([uselocalhtmlfolder isEqual:@“true”]){NSURL * urllocal = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@“index”ofType:@“html”]]; [_webView loadRequest:[NSURLRequest requestWithURL:urllocal]]; } else {if([onlinecheck length] == 0){_offline.hidden = false; _webView.hidden = true; _text1.hidden = false; _text2.hidden = false; _tryButton.hidden = false; _loadingSign.hidden = true; }其他{NSURLRequest * request = [NSURLRequest requestWithURL:url];

        [_webView loadRequest:request];
    }
    

    } NSUserDefaults * user = [NSUserDefaults standardUserDefaults]; 函数srand(时间(NULL)); int randnum = arc4random()%10; if([user boolForKey:@“ratemyapp”] == 0){{if(randnum == 1){[user setObject:[NSString stringWithFormat:@“1”] forKey:@“ratemyapp”]; [用户同步]; [UIAlertView alertViewWithTitle:ratemyapptitle message:ratemyapptext cancelButtonTitle:ratemyappno otherButtonTitles:[NSArray arrayWithObjects:ratemyappyes,nil] onDismiss:^(int buttonIndex){NSString * prefeedback = [NSString stringWithFormat:ratemyappurl]; NSURL * feedback = [NSURL URLWithString:prefeedback]; [[UIApplication sharedApplication] openURL:feedback]; } onCancel:^(){}]; }}} if([user boolForKey:@“becomefbfriends”] == 0){{if(randnum == 2){[user setObject:[NSString stringWithFormat:@“1”] forKey:@“becomefbfriends”]; [用户同步]; [UIAlertView的alertViewWithTitle:成为facebookfriendstitle消息:成为facebookfriendstextcancelButtonTitle:成为facebookfriendsnootherButtonTitles:[NSArray arrayWithObjects:becomefacebookfriendsyes,nil] onDismiss:^(int buttonIndex){NSString * prefeedback = [NSString stringWithFormat:becomefacebookfriendsurl]; NSURL * feedback = [NSURL URLWithString:prefeedback]; [[UIApplication sharedApplication] openURL:feedback]; } onCancel:^(){}]; }}} if([user boolForKey:@“firstrun”] == 0){{UIAlertView * showfirstrunmessage = [[UIAlertView alloc] initWithTitle:firstrunmessagetitle message:firstrunmessage delegate:self cancelButtonTitle:okbutton otherButtonTitles:nil]; [user setObject:[NSString stringWithFormat:@“1”] forKey:@“firstrun”]; [用户同步]; [showfirstrunmessage show]; }}

  • }

  • (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning]; //处理任何可以重新创建的资源。 }

  • (IBAction)tryagain:(id)sender {NSURL * url = [NSURL URLWithString:webviewurl]; NSString * onlinecheckagain = [[NSString alloc] initWithContentsOfURL:url]; if([onlinecheckagain length] == 0){UIAlertView * alert = [[UIAlertView alloc] initWithTitle:offlinetitle message:offlinemsg delegate:self cancelButtonTitle:okbutton otherButtonTitles:nil]; [警示]; } else {_offline.hidden = true; _text1.hidden = true; _text2.hidden = true; _tryButton.hidden = true; _webView.hidden = false; NSURLRequest * request = [NSURLRequest requestWithURL:url]; [_webView loadRequest:request]; }

  • }

  • (void)webViewDidStartLoad:(UIWebView *)webView {[_loadingSign startAnimating]; _loadingSign.hidden = false;
  • } - (void)webViewDidFinishLoad:(UIWebView *)webView {[_loadingSign stopAnimating]; _loadingSign.hidden = true; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError)error {NSURLurl = [NSURL URLWithString:webviewurl];

    NSString *onlinecheckagain = [[NSString alloc] initWithContentsOfURL:url];
    if ([onlinecheckagain length] == 0) {
        webView.hidden = true;
        _loadingSign.hidden = true;
        _offline.hidden = false;
        _text1.hidden = false;
        _text2.hidden = false;
        _tryButton.hidden = false;
    }}
    

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {NSURL * requestURL = [request URL]; if([[requestURL host] isEqualToString:@“push.send.cancel”]){[[UIApplication sharedApplication] cancelAllLocalNotifications]; return NO;} if([[requestURL host] isEqualToString:@“push.send”]){NSURL * prerequest = requestURL; NSString *完成= [prerequest absoluteString]; NSArray * requested = [finished componentsSeparatedByString:@“=”]; NSString * seconds = [requested objectAtIndex:1]; NSArray * logindetails = [完成componentsSeparatedByString:@“msg!”]; NSString * logindetected = [logindetails objectAtIndex:1]; NSArray * logindetailsmore = [logindetected componentsSeparatedByString:@“&!#”]; NSString * msg0 = [logindetailsmore objectAtIndex:0]; NSString * button0 = [logindetailsmore objectAtIndex:1]; NSString * msg = [msg0 stringByReplacingOccurrencesOfString:@“%20”withString:@“”]; NSString * button = [button0 stringByReplacingOccurrencesOfString:@“%20”withString:@“”]; double sendafterseconds = [seconds doubleValue]; UILocalNotification * pushmsg1 = [[UILocalNotification alloc] init]; pushmsg1.fireDate = [[NSDate date] dateByAddingTimeInterval:sendafterseconds]; pushmsg1.timeZone = [NSTimeZone defaultTimeZone]; pushmsg1.alertBody = msg; pushmsg1.soundName = UILocalNotificationDefaultSoundName; pushmsg1.alertAction = button; [[UIApplication sharedApplication] scheduleLocalNotification:pushmsg1]; 返回NO; }([uselocalhtmlfolder isEqual:@“true”]){if(([[requestURL scheme] isEqualToString:@“http”] || [[requestURL scheme] isEqualToString:@“https”] || [[requestURL scheme] isEqualToString:@“mailto”])&&(navigationType == UIWebViewNavigationTypeLinkClicked)){[[UIApplication sharedApplication] openURL:requestURL]; 返回NO; } else {return YES; }} else {if([openallexternalurlsinsafaribydefault isEqual:@“true”]){NSString * predefaulthost = [webviewurl stringByReplacingOccurrencesOfString:@“http://”withString:@“”]; NSString * defaulthost = [predefaulthost stringByReplacingOccurrencesOfString:@“https://”withString:@“”]; if([[requestURL host] isEqualToString:defaulthost]){} else {[_ LoadSign stopAnimating]; _loadingSign.hidden = true; [[UIApplication sharedApplication] openURL:requestURL]; 返回NO;}}

        /* Open specific URL "http://maps.google.com" links in Safari START */
        if ([[requestURL host] isEqualToString:@"maps.google.com"]) /* WITHOUT HTTP/HTTPS */{
            [_loadingSign stopAnimating];
            _loadingSign.hidden = true;
            [[UIApplication sharedApplication] openURL:requestURL];
            return NO;
        } /* Open specific URL "http://maps.google.com" links in Safari END */
    
    
    
        return YES;
    }
    

    } @结束

    链接地址: http://www.djcxy.com/p/34859.html

    上一篇: Parse push json IOS webview

    下一篇: Relative Paths not working on apache2 web server