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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:17:36+00:00 2026-06-17T16:17:36+00:00

In my app, I am trying to do a simple thing – save a

  • 0

In my app, I am trying to do a simple thing – save a txt file and an image file into iCloud and then retrieve it back to open it on the app.

Right now, I can save both txt and image files into iCloud – no problem. I can even pull the URLs and the file names of the documents from iCloud – no problem there as well. But my question is, how do I open the txt file? What a sample code to open a txt file from iCloud and get the text contents? My txt file document is a subclass of UIDocument, if that helps.

  • 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-06-17T16:17:38+00:00Added an answer on June 17, 2026 at 4:17 pm

    well I notice it’s like 4 months after you asked this question. Maybe this will be help for other seeking souls here.

    Basically, on iOS you open a UIDocument first by querying all documents, then by opening what iCloud responds you with.
    Here’s how you start a query:

    NSURL *baseURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
    if (baseURL)
    {
        _metadataQuery = [[NSMetadataQuery alloc] init];
        [_metadataQuery setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]];
    
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like '*'", NSMetadataItemFSNameKey];
        [_metadataQuery setPredicate:predicate];
    
        CL_DLog(@"Start query - %d",[_metadataQuery startQuery]);
    }
    

    Before doing code above, subscribe to these notifications to receive response

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinish:) name:NSMetadataQueryDidFinishGatheringNotification object:_metadataQuery];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinish:) name:NSMetadataQueryDidUpdateNotification object:_metadataQuery];
    

    Then in your response you can open the document

    YourUIDocumentClassName *document = [[YourUIDocumentClassName alloc] initWithFileURL:documentURL];

    if ([document documentState] != UIDocumentStateClosed)
    {
        CL_DLog(@"FYI - metadata document state is not StateClosed.");
    }
    
    [document openWithCompletionHandler:^(BOOL success) {
    ....
    

    You can check Apple’s session on icloud and UIDocument https://developer.apple.com/videos/wwdc/2012/?id=218

    Hope it helps.

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

Sidebar

Related Questions

I'm trying to do a simple thing; read an image from the internet, save
I've been trying to implement simple (I think) thing in my app. I thought
I'm writing a simple app in HTML and Javascript. I'm trying to retrieve my
I have following app. I am trying to do a very simple thing .
I'm trying to add simple login page to ASP.NET MVC app. I actually use
In my Java app I am trying to create a very simple form with
I am fairly new to iOS development and trying make a simple app which
I am trying to do a simple app that will send email. The constructor
Im trying to create a simple pan and zoom app using silverlight 4, but
I'm trying to make a simple app that sits on the Mac OSX menu

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.