解析json IOS webview

时间:2016-02-11 20:38:24

标签: ios json parse-platform webview

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

import" ViewController.h"

@interface ViewController()

///插页式广告。

@end

@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] bounds]; 双状态栏= 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; if([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                                 消息: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:becomefacebookfriendstitle                                 消息:becomefacebookfriendstext                       cancelButtonTitle:becomefacebookfriendsno                       otherButtonTitles:[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];     [警示显示]; } 其他{     _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 {     NSURL url = [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 = [请求网址];     if([[requestURL host] isEqualToString:@" push.send.cancel"]){[[UIApplication sharedApplication] cancelAllLocalNotifications];返回NO;}     if([[requestURL host] isEqualToString:@" push.send"]){         NSURL * prerequest = requestURL;         NSString * finished = [prerequest absoluteString];         NSArray * requested = [finished componentsSeparatedByString:@" ="];         NSString * seconds = [requested objectAtIndex:1];         NSArray * logindetails = [finished 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;     }     if([uselocalhtmlfolder isEqual:@" true"]){         if(([[requestURL scheme] isEqualToString:@" http"] || [[requestURL scheme] isEqualToString:@" https"] || [[requestURL scheme] isEqualToString:@& #34; mailto"])&&(navigationType == UIWebViewNavigationTypeLinkClicked)){             [[UIApplication sharedApplication] openURL:requestURL];             返回NO;         }其他{             返回YES;         }     }     其他{         if([openallexternalurlsinsafaribydefault isEqual:@" true"]){             NSString * predefaulthost = [webviewurl stringByReplacingOccurrencesOfString:@" http://" withString:@""];             NSString * defaulthost = [predefaulthost stringByReplacingOccurrencesOfString:@" https://" withString:@""];             if([[requestURL host] isEqualToString:defaulthost]){} else {[_ loadingSign 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;
}

} @end

0 个答案:

没有答案