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

  • Home
  • SEARCH
  • 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 4074762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:12:43+00:00 2026-05-20T17:12:43+00:00

I have written code like this but I can’t understand how to find if

  • 0

I have written code like this but I can’t understand how to find if the data is present or not in the URL. Can anyone help me in solving this problem?

Note: This code terminates when the loop is entering the second condition. That is where it’s terminating.

-(void)getdetails
{   

    NSLog(@"in get details");
    NSURL *jsonurl=[NSURL URLWithString:@"http://www.myappdemo.com/checkout/services/getonlineusers.php"];
    NSMutableURLRequest *request=[[[NSMutableURLRequest alloc]init ]autorelease];

    [request setURL:jsonurl];
    [request setHTTPMethod:@"POST"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    NSError *error;
    NSURLResponse *response;
    NSData *serverReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *replyString = [[NSString alloc] initWithBytes:[serverReply bytes] length:[serverReply length] encoding: NSASCIIStringEncoding];

    if([replyString isEqualToString:@"Invalid."]){ // i have not set the php code to output "invalid" so this will not work for now ...

        NSLog(@"%@",replyString);
    }
    else {
        NSMutableArray *tempArray =[replyString JSONValue];

        int count=0;
        self.temparray=tempArray;

        for(int i=0;i<[tempArray count];i++)
        {
            ///////Here in this loop when it is entering it is terminating /////////

            NSDictionary *dict=[tempArray objectAtIndex:i];
            NSLog(@"DICT is %@",dict);

            NSString *string=[dict objectForKey:@"profilepic"];
            NSURL *finalURL = [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
            NSLog(@"encoding string is %@",finalURL);
            NSURL *url=[NSURL URLWithString:string];
            NSString *source = [NSString stringWithContentsOfURL:finalURL encoding:NSUTF8StringEncoding error:nil];
            NSFileManager *fileManager = [NSFileManager defaultManager];
            BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:url];
            NSLog(@"url is %@",url);
            NSData *data=[NSData  dataWithContentsOfURL:url];

            if(!(data==nil))
            {
        NSLog(@"data is there");

                UIImage *image=[[UIImage alloc]initWithData:data];

                [self.array addObject:image];
                [image release];
            }
            else {
                /*
                NSLog(@"if data is null condition block");
                UIImage *image=[[UIImage alloc]init];
                [self.array addObject:image];
                [image release];    
                */
            }

            count=count+1;

            NSLog(@"count is %d",count);

        }

    }

    [replyString release];
}
  • 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-20T17:12:44+00:00Added an answer on May 20, 2026 at 5:12 pm

    Where does the app terminate and what is the exception? Have you stepped through to see what the array object looks like during each iteration? Is it failing at NSData initWithContentsOfURL? Why don’t you issue that as a separate synchronous request and test to see if you got a response?

    Regarding your first (and any subsequent) synchronous request, it would probably be good to add a check to ensure you received a valid response (sorry for the formatting, the code tag isn’t playing nicely at the moment)

    if (response!=nil) {if([response isKindOfClass:[NSHTTPURLResponse class]]) {
    // you have a valid response }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code which will does not work but the second
I have just been re-working an old bit of compiler-like code written using bison.
I have lots of Java code written by other people and not residing in
I have written code that automatically creates CSS sprites based on the IMG tags
I have written some code in my VB.NET application to send an HTML e-mail
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have written a few modules of code in Access vba. Each code runs
Here's a snippet of code from a shell script I have written: for src
Put it another way: what code have you written that cannot fail. I'm interested
I have a code snippet written in PHP that pulls a block of text

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.