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 6675501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:51:51+00:00 2026-05-26T03:51:51+00:00

In the method transmitData, the NSArray files is coming up nil. Where is the

  • 0

In the method transmitData, the NSArray files is coming up nil. Where is the problem in my code? I save a file (we hit [file writeToURL: fileURL atomically: YES]) and then we call transmitData, but cannot retrieve the files.

#import "FileManagerService.h"
#import "SynthesizeSingleton.h"
@implementation FileManagerService
SYNTHESIZE_SINGLETON_FOR_CLASS(FileManagerService);

#define SAVEVOTER @"SV"
#define SAVESCRIPT @"SS"

- (NSURL *)applicationDocumentsDirectory 
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory   inDomains:NSUserDomainMask] lastObject];
}

-(void)saveFile:(NSData*)file:(NSString*)dataType
{
NSFileManager *manager = [NSFileManager defaultManager];
NSURL *fileURL;
NSString *fileName;

if (dataType == DATA_SAVE_VOTER)
{
    fileName = [NSString stringWithFormat:@"%@01",SAVEVOTER];
    fileURL = [[self applicationDocumentsDirectory]URLByAppendingPathComponent:fileName];

    int fID = 0;

    while ([manager fileExistsAtPath:[fileURL absoluteString]]) 
    {
        fID++;

        fileName = [NSString stringWithFormat:@"%@%d",SAVEVOTER,fID];
        fileURL = [[self applicationDocumentsDirectory]URLByAppendingPathComponent:fileName];
    }

}
else if (dataType == DATA_SAVE_SCRIPT)
{
    fileName = [NSString stringWithFormat:@"%@01",SAVESCRIPT];
    fileURL = [[self applicationDocumentsDirectory]URLByAppendingPathComponent:fileName];

    int fID = 0;

    while ([manager fileExistsAtPath:[fileURL absoluteString]]) 
    {
        fID++;

        fileName = [NSString stringWithFormat:@"%@%d",SAVESCRIPT,fID];
        fileURL = [[self applicationDocumentsDirectory]URLByAppendingPathComponent:fileName];
    }

}


[file writeToURL:fileURL atomically:YES];
}


-(void)transmitData
{
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[[self applicationDocumentsDirectory]absoluteString] error:NULL];

if (files == nil || [files count] <= 0)
{
    NSLog(@"No files to transmit");
    return;
}

for (id file in files) 
{ 
    NSData * dt = file;
    NSString *str = [[NSString alloc]initWithData:dt encoding:NSUTF8StringEncoding];

    NSLog(@"DataContents: %@",str);
}
}

@end

EDIT:
Upon more testing :

fileName = @"testfile";
    fileURL = [[self    applicationDocumentsDirectory]URLByAppendingPathComponent:fileName];

        NSLog(@"URL1: %@",[fileURL absoluteString]);

My log is coming up Null. So I cant retrieve files because I am obviously saving with a null file location….why is this happening?

FIXED:

So I have no idea why, but [file writeToURL:fileURL atomically:YES] does NOT work and [[NSFileManager defaultManager] createFileAtPath:fileURL
contents:file
attributes:nil];
does work.

  • 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-26T03:51:52+00:00Added an answer on May 26, 2026 at 3:51 am

    Use

    - (NSURL *)applicationDocumentsDirectory
    {
        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentPath = [searchPaths objectAtIndex:0];
    
        return [NSURL fileURLWithPath:documentPath];
    }
    

    and

    NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[[self applicationDocumentsDirectory]path] error:NULL];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The method definitions in any winform's *.Designer.cs file created by Visual Studio are not
Using method: System.IO.File.Create() After the file gets created, it still remains used by a
RetainAll method function is in java what is alternative method in objective-C sample code
My method is too slow. The result in 265 files it gives me in
Method chaining is the only way I know to build fluent interfaces. Here's an
Method chaining is the practice of object methods returning the object itself in order
Method keySet() . Examples works fine, but I not sure if I'm right.
What method do you use when you want to get performance data about specific
Every method I write to encode a string in Java using 3DES can't be
What method do I call to get the name of a class?

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.