Parse push json IOS webview

I have an ios webview app and I am trying to push links to articles. I for the life of me can't figure out how to do it. Each notification just opens the home page. Any help out there? I am 100% new at this so if you can please explain it to me like the idiot I am.

import "ViewController.h"

@interface ViewController ()

/// The interstitial ad.

@end

@implementation ViewController { }

  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.

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

    // On iOS 6 ADBannerView introduces a new initializer, use it when available. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;

    CGRect phonecheck = [[UIScreen mainScreen] bounds]; 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; 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; } else { NSURLRequest *request = [NSURLRequest requestWithURL:url];

        [_webView loadRequest:request];
    }
    

    } NSUserDefaults *user = [NSUserDefaults standardUserDefaults]; srand(time(NULL)); int randnum = arc4random()%10; if ([user boolForKey:@"ratemyapp"] == 0) { { if (randnum==1){ [user setObject:[NSString stringWithFormat:@"1"] forKey:@"ratemyapp"]; [user synchronize]; [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"]; [user synchronize]; [UIAlertView alertViewWithTitle:becomefacebookfriendstitle message: 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"]; [user synchronize]; [showfirstrunmessage show]; }}

  • }

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

  • (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]; [alert show]; } 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 *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]; return NO; } if ([uselocalhtmlfolder isEqual: @"true"]) { if ( ( [ [ requestURL scheme ] isEqualToString: @"http" ] || [ [ requestURL scheme ] isEqualToString: @"https" ] || [ [ requestURL scheme ]isEqualToString: @"mailto" ]) && ( navigationType == UIWebViewNavigationTypeLinkClicked ) ) { [[UIApplication sharedApplication] openURL:requestURL]; return 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{[_loadingSign stopAnimating]; _loadingSign.hidden = true; [[UIApplication sharedApplication] openURL:requestURL]; return 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

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

    上一篇: 在uiwebview中使用本地html从相对路径加载资源

    下一篇: 解析推送JSON IOS webview