SlideShare a Scribd company logo
iCloud

                Mick Kubo(@komarineko)
                    http://komarineko.net/


                      2012    1   21




12   2   14
•   iCloud
                                            ...

                                              ....


              •   NSDocument
                                            ...
                                                         ...
                  Web                ...(            )


              •                ...




12   2   14
iCloud
                   •                 (                           )
                   •                 (                                )


                   •   Apple
                                                        ...

                   •           ...
                                               Google Evernote


                   •   WWDC2011 iCloud
                                                      Windows        API
                                         ...




12   2   14
•   iCloud
                                                iCloud


              •            daemon ”ubd”
              •
              •
                  iCloud
                                 “ubd”    (ry




12   2   14
• NSFilePresenter
              • NSFileCoordinator
              •
              •          UIDocument




12   2   14
UIDocument
              • NSFilePresenter
              •                 UIDocument
                loadFromContents:ofType:error: (   )    contentsForType:error: (   )


                         (ViewController)          delegate




12   2   14
UIDocument
              • delegate                   (→View    )
              • View                      →
              •UIDocumentStateChangedNotification
               [NSNotificationCenter defaultCenter]
                              documentState
               	

  UIDocumentStateNormal :
               	

  UIDocumentStateInConflict :
               	

  UIDocumentStateSavingError
               UIDocumentStateNormal




12   2   14
• iCloud
                defaultFileManager ( [NSFileManager defaultManager] )
                URLForUbiquityContainerIdentifier:
                  →iCloud
                     nil    iCloud
                iCloud                        iCloud




12   2   14
•   NSMetadataQuery

                        )
                  	

       NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
                  	

       query.predicate = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey];
                  	

       query.searchScopes = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope];
                  	

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUbiquitousDocuments:)
                  	

       	

     	

     	

    	

     	

     name:NSMetadataQueryDidFinishGatheringNotification object:nil];
                  	

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUbiquitousDocuments:)
                  	

       	

     	

     	

    	

     	

     name:NSMetadataQueryDidUpdateNotification object:nil];
                  	

       [query startQuery];




12   2   14
•
                  saveToURL:forSaveOperation:completionHandler:
                  	

   forSaveOperation UIDocumentSaveForCreating


              •
                  openWithCompletionHandler:


              •
                  closeWithCompletionHandler:
                                                         (    )



12   2   14
• iCloud                                (
                  defaultFileManager ( [NSFileManager defaultManager] )
                                                                          )
                  setUbiquitous:itemAtURL:destinationURL:error:
                  	

                            → iCloud
                  	

    	

  setUbiquitous YES
                  	

    iCloud                        →
                  	

    	

  setUbiquitous NO


              •   defaultFileManager ( [NSFileManager defaultManager] )
                  removeItemAtURL:error:




12   2   14
• iCloud
                setUbiquitous:itemAtURL:destinationURL:error:
                                                                             (                                            )

                	

        NSFilePresenter
                	



                      )(               iOS                                                                               )
                	

        dispatch_queue_t q_default;
                	

        q_default = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                	

        dispatch_async(q_default, ^(void) {
                	

        	

        NSFileManager *fileManager = [[NSFileManager alloc] init];
                	

        	

     NSError *error = nil;
                	

        	

     BOOL success = [fileManager setUbiquitous:YES itemAtURL:sourceURL
                	

        	

     	

      	

      	

     	

     	

     destinationURL:destinationURL error:&error];
                	

        	

     dispatch_queue_t q_main = dispatch_get_main_queue();
                	

        	

     dispatch_async(q_main, ^(void) {
                	

        	

     	

      if (success) {
                	

        	

     	

      	

      FileRepresentation *fileRepresentation = [[FileRepresentation alloc]
                	

        	

     	

      	

      	

     	

     initWithFileName:fileToMove.fileName url:destinationURL];
                	

        	

     	

      	

      [_fileList removeObject:fileToMove];
                	

        	

     	

      	

      [_fileList addObject:fileRepresentation];
                	

        	

     	

      	

      NSLog(@"moved file to cloud: %@", fileRepresentation);
                	

        	

     	

      }
                	

        	

     	

      if (!success) {
                	

        	

     	

      	

      NSLog(@"Couldn't move file to iCloud: %@", fileToMove);
                	

        	

     	

      }
                	

        	

     });
                	

        });


12   2   14
•


              •


12   2   14

More Related Content

PDF
Beginning icloud development - Cesare Rocchi - WhyMCA
PDF
Bonjour, iCloud
PDF
Persisting Data on SQLite using Room
PDF
iOS for ERREST - alternative version
PDF
ERGroupware
KEY
Whats new in iOS5
KEY
iOSDevCamp 2011 Core Data
PDF
Zabbix LLD from a C Module by Jan-Piet Mens
Beginning icloud development - Cesare Rocchi - WhyMCA
Bonjour, iCloud
Persisting Data on SQLite using Room
iOS for ERREST - alternative version
ERGroupware
Whats new in iOS5
iOSDevCamp 2011 Core Data
Zabbix LLD from a C Module by Jan-Piet Mens

What's hot (20)

PDF
Arquitetando seu aplicativo Android com Jetpack
PPTX
The next step, part 2
PDF
I os 04
PDF
Core Data with multiple managed object contexts
PPTX
iOS Beginners Lesson 4
KEY
コードで学ぶドメイン駆動設計入門
PPTX
20141001 delapsley-oc-openstack-final
PDF
Create a Core Data Observer in 10mins
PPTX
Client-side Rendering with AngularJS
KEY
Data perisistence in iOS
PDF
Realm.io par Clement Sauvage
ODP
MobileCity:Core Data
KEY
Core animation
PDF
mDevCamp - The Best from Google IO
PDF
Green dao
PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
KEY
Special Events: Beyond Custom Events
PDF
Symfony Day 2010 Doctrine MongoDB ODM
PDF
REST/JSON/CoreData Example Code - A Tour
PPTX
Getting Started with Datatsax .Net Driver
Arquitetando seu aplicativo Android com Jetpack
The next step, part 2
I os 04
Core Data with multiple managed object contexts
iOS Beginners Lesson 4
コードで学ぶドメイン駆動設計入門
20141001 delapsley-oc-openstack-final
Create a Core Data Observer in 10mins
Client-side Rendering with AngularJS
Data perisistence in iOS
Realm.io par Clement Sauvage
MobileCity:Core Data
Core animation
mDevCamp - The Best from Google IO
Green dao
Mythbusting: Understanding How We Measure the Performance of MongoDB
Special Events: Beyond Custom Events
Symfony Day 2010 Doctrine MongoDB ODM
REST/JSON/CoreData Example Code - A Tour
Getting Started with Datatsax .Net Driver
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf
A Presentation on Artificial Intelligence
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Monthly Chronicles - July 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
Ad

20120121

  • 1. iCloud Mick Kubo(@komarineko) http://komarineko.net/ 2012 1 21 12 2 14
  • 2. iCloud ... .... • NSDocument ... ... Web ...( ) • ... 12 2 14
  • 3. iCloud • ( ) • ( ) • Apple ... • ... Google Evernote • WWDC2011 iCloud Windows API ... 12 2 14
  • 4. iCloud iCloud • daemon ”ubd” • • iCloud “ubd” (ry 12 2 14
  • 5. • NSFilePresenter • NSFileCoordinator • • UIDocument 12 2 14
  • 6. UIDocument • NSFilePresenter • UIDocument loadFromContents:ofType:error: ( ) contentsForType:error: ( ) (ViewController) delegate 12 2 14
  • 7. UIDocument • delegate (→View ) • View → •UIDocumentStateChangedNotification [NSNotificationCenter defaultCenter] documentState UIDocumentStateNormal : UIDocumentStateInConflict : UIDocumentStateSavingError UIDocumentStateNormal 12 2 14
  • 8. • iCloud defaultFileManager ( [NSFileManager defaultManager] ) URLForUbiquityContainerIdentifier: →iCloud nil iCloud iCloud iCloud 12 2 14
  • 9. NSMetadataQuery ) NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; query.predicate = [NSPredicate predicateWithFormat:@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey]; query.searchScopes = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUbiquitousDocuments:) name:NSMetadataQueryDidFinishGatheringNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUbiquitousDocuments:) name:NSMetadataQueryDidUpdateNotification object:nil]; [query startQuery]; 12 2 14
  • 10. saveToURL:forSaveOperation:completionHandler: forSaveOperation UIDocumentSaveForCreating • openWithCompletionHandler: • closeWithCompletionHandler: ( ) 12 2 14
  • 11. • iCloud ( defaultFileManager ( [NSFileManager defaultManager] ) ) setUbiquitous:itemAtURL:destinationURL:error: → iCloud setUbiquitous YES iCloud → setUbiquitous NO • defaultFileManager ( [NSFileManager defaultManager] ) removeItemAtURL:error: 12 2 14
  • 12. • iCloud setUbiquitous:itemAtURL:destinationURL:error: ( ) NSFilePresenter )( iOS ) dispatch_queue_t q_default; q_default = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(q_default, ^(void) { NSFileManager *fileManager = [[NSFileManager alloc] init]; NSError *error = nil; BOOL success = [fileManager setUbiquitous:YES itemAtURL:sourceURL destinationURL:destinationURL error:&error]; dispatch_queue_t q_main = dispatch_get_main_queue(); dispatch_async(q_main, ^(void) { if (success) { FileRepresentation *fileRepresentation = [[FileRepresentation alloc] initWithFileName:fileToMove.fileName url:destinationURL]; [_fileList removeObject:fileToMove]; [_fileList addObject:fileRepresentation]; NSLog(@"moved file to cloud: %@", fileRepresentation); } if (!success) { NSLog(@"Couldn't move file to iCloud: %@", fileToMove); } }); }); 12 2 14
  • 13. • 12 2 14