Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7625149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:09:14+00:00 2026-05-31T05:09:14+00:00

I’m developing an iOS 4 app for iPad with latest SDK and XCode 4.2.

  • 0

I’m developing an iOS 4 app for iPad with latest SDK and XCode 4.2.

I have a problem with a JSON web service. I’m using a timer to check every 3 seconds if some data has changed. The problem is that data changes, but I can’t see that changes on my app.

Data received asynchronously is always the same. It is like NSURLConnection has a cache or something like that, and it always returning the first data it takes.

Here is my code:

ControlPanelJSON.h

#import <Foundation/Foundation.h>
#import "SBJson.h"
#import "WebServiceDelegate.h"

@interface ControlPanelJSON : NSObject
{
    SBJsonParser* parser;
    NSURLRequest* request;
    NSMutableData* receivedData;

    BOOL isEncuestaVisible;
    BOOL isInfoVisible;
    BOOL isTwitterVisible;

    id<WebServiceDelegate> delegate;
}
@property (nonatomic, readonly) BOOL isEncuestaVisible;
@property (nonatomic, readonly) BOOL isInfoVisible;
@property (nonatomic, readonly) BOOL isTwitterVisible;

- (id) initWithWebServiceURLString:(NSString*)webServiceURL
                          delegate:(id<WebServiceDelegate>)del;

- (void)callWebService;

@end

ControlPanelJSON.m

#import "ControlPanelJSON.h"

#define kRootKey @"s"
#define kControlKey @"c"
#define kEstadoKey @"e"

#define kEncuestaTitle @"[ zzz ]"
#define kInfoTitle @"[ yyy ]"
#define kTwitterTitle @"[ xxx ]"

@implementation ControlPanelJSON

@synthesize isEncuestaVisible;
@synthesize isInfoVisible;
@synthesize isTwitterVisible;

- (id) initWithWebServiceURLString:(NSString*)webServiceURL
                          delegate:(id<WebServiceDelegate>)del
{
    if (self = [super init])
    {
        delegate = [del retain];
        request = [[NSURLRequest alloc] initWithURL: [NSURL URLWithString: webServiceURL]
                                        cachePolicy: NSURLCacheStorageNotAllowed
                                    timeoutInterval: 60.0];
        parser = [[SBJsonParser alloc] init];
    }
    return self;
}

- (void) dealloc
{
    [parser release];
    [request release];
    [receivedData release];

    [super dealloc];
}

- (void)callWebService
{
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
    if (theConnection)
    {
        // Create the NSMutableData to hold the received data.
        // receivedData is an instance variable declared elsewhere.
        receivedData = [[NSMutableData data] retain];
    }
    else
    {
        [delegate errorReceivedWithMessage:NSLocalizedString(@"CONNERROR", nil)];
    }
}

#pragma mark -
#pragma mark - NSURLConnectionDelegate

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    // This method is called when the server has determined that it
    // has enough information to create the NSURLResponse.

    // It can be called multiple times, for example in the case of a
    // redirect, so each time we reset the data.

    // Cuando se recibe este mensaje se debe descartar todo lo recibido anteriormente.
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    // Append the new data to receivedData.
    // receivedData is an instance variable declared elsewhere.
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
    // release the connection, and the data object
    [connection release];
    // receivedData is declared as a method instance elsewhere
    [receivedData release];

    // inform the user
    [delegate errorReceivedWithMessage:
     [NSString stringWithFormat:@"Error - %@ %@",
      [error localizedDescription],
      [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]]];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{   
    NSString *json_string = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
    NSDictionary* datos = [parser objectWithString:json_string error:nil]; // TODO: Otro error que manejar

    [connection release];
    //[receivedData release];
    //[parser release];
    [json_string release];

    NSArray* data = [datos objectForKey:kRootKey];
    for (int i = 0; i < data.count; i++)
    {
        NSDictionary* object = [data objectAtIndex:i];
        NSString* controlName = [object objectForKey:kControlKey];
        NSString* controlEstado = [object objectForKey:kEstadoKey];

        if ([controlName isEqualToString: kEncuestaTitle])
        {
            isEncuestaVisible = ([controlEstado isEqualToString: @"1"]);
            continue;
        }
        else if ([controlName isEqualToString: kInfoTitle])
        {
            isInfoVisible = ([controlEstado isEqualToString: @"1"]);
            continue;
        }
        else if ([controlName isEqualToString: kTwitterTitle])
        {
            isTwitterVisible = ([controlEstado isEqualToString: @"1"]);
            continue;
        }
    }

    [delegate dataReceived];
}

@end

After this code line:

NSString *json_string = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];

I added a NSLog, and I always getting the same json_string

{“ctrls”: [ { “control”: “[ xxx ]”,”estado”: “0” },{ “control”: “[ yyy ]”,”estado”: “0” },{ “control”: “[ zzz ]”,”estado”: “0” } ] }

Any clue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:09:15+00:00Added an answer on May 31, 2026 at 5:09 am

    Try changing the cache policy when you create your NSURLRequest to:

    NSURLRequestReloadIgnoringLocalAndRemoteCacheData
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.