SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Xamarin
   Seminar
     22nd March 2012
    Copyright 2012 Š Xamarin Inc. All rights reserved
Announcements
 http://xamarin.com/seminars




                                                           Xamarin
       Copyright 2012 Š Xamarin Inc. All rights reserved
Agenda
iCloud with MonoTouch

                      Craig Dunn
                      Technical Writer
                      Xamarin Documentation Team
                      craig.dunn@xamarin.com




                                                       Xamarin
   Copyright 2012 Š Xamarin Inc. All rights reserved
Introduction
This session discusses Apple’s new iOS5 iCloud
functionality and how to implement iCloud features
with MonoTouch.
We’ll cover:
• iCloud Basics & Setup
• iCloud Key-Value Storage
• iCloud Document Storage
• iCloud Backup (iOS Data Storage Guidelines)



                                                                     Xamarin
                 Copyright 2012 Š Xamarin Inc. All rights reserved
iCloud Basics (i)
   • Remote storage & backup
   • Synchronization of data across devices (iOS
     & Mac OS X) but NOT conflict resolution
     • OS process controls sending/receiving
                                               Cloud
iPhone     Local storage
                                              storage          Local storage




                                                                iCloud Daemon
         iCloud Daemon

                              iCloud Daemon
                                                                                Mac


                           Local storage
                                                        iPad
iCloud Basics (ii)
• 4 ways to utilize iCloud:
   • Key-Value Pairs           today’s
                                topic
   • UIDocument
   • CoreData                  another
   • Individual files/folders    time...
iCloud Setup (i)
• App ID & Provisioning Profile (developer.apple.com)
   • grants iCloud support (tick the box!)
   • linked to your TeamID and the BundleID
• Entitlements.plist (in your project)
   • specify TeamID & BundleID
   • use these keys:
 com.apple.developer.ubiquity-kvstore-identifier
 com.apple.developer.ubiquity-container-identifiers
iCloud Setup (iii)
• MonoDevelop Entitlements UI with placeholder
   expansion:
     • $(TeamPrefixIdentifier) automatically added
     • $(CFBundleIdentifier) for the default
         ubiquity-identier

          han it
 E asier t ith
   l ooks, w lop!
 Mono   Deve
iCloud Setup (iv)
• Don’t forget the devices!
  • Same AppleID on each device
Key-Value Pairs (i)
• Similar to NSUserDefaults
• Simple types only (whatever works in a plist):
  text, number, date
• Limited size:
   • 64Kb total
   • 64Kb max per key too
• Recommendation: use NSUserDefaults and
  ‘shadow’ with iCloud Key-Value pairs
Key-Value Pairs (ii)


Example creates
 a ‘key’ for each
  device, plus a
   Shared one.
Key-Value Pairs (iii)
• SetString

• GetString

• Synchronize() returns false if no iCloud OR
  if no updates are required
• Your app should run even if the Key-Values
  are empty! (sounds obvious, but...)
Key-Value Pairs (iv)
           • Change Notifications
                                   Register for notication



ServerChange
InitialSyncChange
QuotaViolationChange


Tells us which keys                            NSArray of IntPtrs
have changed values



  Loop through the
  keys, get the new
  values and do
  something!
Files in the Cloud
  • NSFileCoordinator & NSFilePresenter work
    with the iCloud to prevent contention on the
    local copy
  • UIDocument hides that complexity from you!
         aka UbiquityContainer                                                    Cloud
                                                                                 storage




                                                                                                                Presenter / Coordinator
                                                                                                     Local
         Presenter / Coordinator




                                      Local                                                         storage
                                     storage




iPhone                             iCloud Daemon
                                                                                                iCloud Daemon
                                                                                                                                          Mac
                                                                   Presenter / Coordinator



                                                   iCloud Daemon




    or just use                                       Local
   UIDocument!                                       storage
                                                                                             iPad
UbiquityContainer                               Ru
                                                                 ki
                                                             Bloc backg
                                                                  a
                                                                        all!
                                                                    ng c round

                                                             n on thread!


•   NSFileManager.DefaultManager.GetUrlForUbiquityContainer()

     •   /private/var/mobile/Library/Mobile%20Documents/
         AAA7MMJKYN~com~xamarin~samples~taskcloud/
            Documents/         (user-visible in Settings)
            <your other stuff>

•   Not to be confused with your app’s home directory

     •   /private/var/mobile/Applications/42871799-
         F2CD-455B-9353-749B15C8AA76/
            TaskCloud.app      (app bundle)
            Documents/         (user-visible in iTunes)
            Library/
            <your other stuff>
UIDocument (spoilers)
• Where are iCloud documents stored?
                          UbiquityContainer   Asyn
                                                  c


• How do you create a UIDoc?
                          UIDoc.Save(ForCreating)              Asyn
                                                                   c

• How do you open one? UIDoc.Open()   Asyn


• How are changes applied? your model on the UIDoc)
                                          c


                          (to
• How do you save it again? UpdateChangeCount()
                          UIDoc.
• What if it changes elsewhere? for notification...
                          Listen
                                                                 Asyn
                                                                       c



• How do you enumerate NSMetadataQuery()
                                                        Asyn
                                                            c
                           UIDocs?
                                                 Asyn
                                                      c
UIDocument (example)
Finding UbiquityContainer
This one line is
key to getting                                     Asyn
                                                       c
iCloud working!




   Do this in FinishedLoading. Apple also recommends
   re-checking each time the app comes to the
   foreground.
Subclassing UIDocument
• Override the ‘read’ and ‘write’ methods:
 • Actually called LoadFromContents() and
    ContentsForType()
• iCloud takes care of when they’re called and
  manages contention at the le system level.
• You NEVER read/write the filesystem directly!
   • Save(CompletionHandler)         As
                                       ync
                                           hro
                                              no
   • Open(CompletionHandler)                    us!


   • UpdateChangeCount
Subclassing UIDocument
                       url to UbiquityContainer location

                                              default value
‘Model’ can be
as simple or
complex as you
like




                                               aka ‘Open’
So we can respond to                           this data
changes if we want




                                       aka ‘Save’ accesses
                                      the model and sends
                                       to lesystem
Create a UIDoc
Put user-generated les in
the /Documents/ directory
                                                Has the ‘(default text)’ set


Save happens                             Asyn
asynchronously, the                          c

completion handler runs
when it is done




  • You could also use
       NSFileManager.DefaultManager.SetUbiquitous() to
       move an existing le from your home directory to
       the UbiquityContainer
Open UIDoc
 Open specic lename
from the /Documents/
 directory
                                 Asyn
                                       c




                                     Might need to be
                                     run on Main thread
Changes Applied & Saved
UpdateChangeCount() is                   Update the model with
all that is required to                  the edited text
signal to iCloud that the
le should be saved*




 * You can implement full undo/redo instead of
 UIDocumentChangeKind.Done
Changes Elsewhere
Listen for notication sent by
the UIDocument subclass
when it is changed




 When that notication
occurs, we are grabbing the
updated text and assigning it
 to the UITextView *


* In a real app, you would probably want to do some
conflict resolution instead...
Enumerate UIDocs (i)
CloudUIDoc example
Looking for a single,
specic lename                                Special Predicate syntax
(monkeyDocFilename)




TaskCloud example (just to show a different query)
      Looking for all                            Special Predicate syntax
      *.task les




                             queryDidFinishGathering on next slide...
Enumerate UIDocs (ii)
When the NSMetadataQuery is done,
we stop it (it could keep running/
monitoring) and remove our listener


 We expect only one le in the
example app; get its “ItemURL” then
create and open the document from
 that location




   • Metadata sync’s faster, so other devices will
        learn if a particular le has been created (even
        though they don’t know the contents)
Debugging Tips (i)
• The /Documents/ directory can be
  managed by the user (and you, for
  testing)
Debugging Tips (ii)
    • Check your iCloud-linked Mac, sync’d files will
       be there if everything is working correctly

/Users/<you>/Library/Mobile Documents/<TeamId><BundleId>/Documents
iOS Data Storage
Guidelines (for iCloud)
• Only documents that are user-generated should
  go into /Documents/
• Data that can be re-created should go into
  /Library/Caches/
• Temp data should be in /tmp/
• Use the “do not backup” attribute to prevent
  ANY les being backed-up to iCloud
Other examples
• Key-Value ~ chat2self
Other examples
• UIDocument ~ TaskCloud
References (i)
Introduction to iOS 5 (currently being updated)
http://docs.xamarin.com/ios/tutorials/Introduction_to_iOS_5

What’s New in iOS
https://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/
Introduction/Introduction.html

TaskCloud - iCloud UIDocument sample
http://conceptdev.blogspot.com.au/2012/03/icloud-uidocument-sample-taskcloud.html
https://github.com/conceptdev/taskcloud

chat2self - iCloud Key-Value sample
http://conceptdev.blogspot.com.au/2012/02/icloud-key-value-example-chat2self.html
https://github.com/conceptdev/Chat2self

iOS Data Storage Guidelines
https://developer.apple.com/icloud/documentation/data-storage/
                                                                                Xamarin
                            Copyright 2012 Š Xamarin Inc. All rights reserved
References (ii)

NSFilePresenter Protocol Reference
http://developer.apple.com/library/mac/#documentation/Foundation/Reference/
NSFilePresenter_protocol/Reference/Reference.html

NSFileCoordinator Class Reference
http://developer.apple.com/library/mac/#documentation/Foundation/Reference/
NSFileCoordinator_class/Reference/Reference.html

iCloud Developer Documentation
https://developer.apple.com/icloud/documentation/




                                                                               Xamarin
                           Copyright 2012 Š Xamarin Inc. All rights reserved
Xamarin
    Seminar
   Please give us your feedback
  http://bit.ly/xamfeedback


      Follow us on Twitter
        @XamarinHQ

         22nd March 2012
        Copyright 2012 Š Xamarin Inc. All rights reserved

Weitere ähnliche Inhalte

Andere mochten auch

Animales de tierra del fuego
Animales de tierra del fuegoAnimales de tierra del fuego
Animales de tierra del fuegoclaudyatdf
 
ResumĂŠ Tradicional
ResumĂŠ Tradicional ResumĂŠ Tradicional
ResumĂŠ Tradicional Keishla49
 
SVT Cloud Security Service 2013
SVT Cloud Security Service 2013SVT Cloud Security Service 2013
SVT Cloud Security Service 2013SVT Cloud Services
 
samel777@hotmail.com
samel777@hotmail.comsamel777@hotmail.com
samel777@hotmail.comADRIANA SILVA
 
A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...
A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...
A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...2016
 
Cultura Santiago Del Estero
Cultura Santiago Del EsteroCultura Santiago Del Estero
Cultura Santiago Del EsteroArani29
 
Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015
Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015
Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015Ilan Lieberman
 
Big Data in the Cloud - Montreal April 2015
Big Data in the Cloud - Montreal April 2015Big Data in the Cloud - Montreal April 2015
Big Data in the Cloud - Montreal April 2015Cindy Gross
 
Open Scotland - Opening up education across Scotland
Open Scotland - Opening up education across ScotlandOpen Scotland - Opening up education across Scotland
Open Scotland - Opening up education across ScotlandLorna Campbell
 

Andere mochten auch (15)

Programa detallado xiv rifrem[1]
Programa detallado xiv rifrem[1]Programa detallado xiv rifrem[1]
Programa detallado xiv rifrem[1]
 
Animales de tierra del fuego
Animales de tierra del fuegoAnimales de tierra del fuego
Animales de tierra del fuego
 
ResumĂŠ Tradicional
ResumĂŠ Tradicional ResumĂŠ Tradicional
ResumĂŠ Tradicional
 
SVT Cloud Security Service 2013
SVT Cloud Security Service 2013SVT Cloud Security Service 2013
SVT Cloud Security Service 2013
 
Tutorial icloud
Tutorial icloudTutorial icloud
Tutorial icloud
 
samel777@hotmail.com
samel777@hotmail.comsamel777@hotmail.com
samel777@hotmail.com
 
A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...
A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...
A cloud-based Personal Learning Environment & Network (PLE&N) for peer-based ...
 
Cultura Santiago Del Estero
Cultura Santiago Del EsteroCultura Santiago Del Estero
Cultura Santiago Del Estero
 
G-Air UP Demo
G-Air UP DemoG-Air UP Demo
G-Air UP Demo
 
Separatism in Quebec
Separatism in QuebecSeparatism in Quebec
Separatism in Quebec
 
Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015
Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015
Forster Dean CPD Chronic Pain Talk Liverpool 11th May 2015
 
Big Data in the Cloud - Montreal April 2015
Big Data in the Cloud - Montreal April 2015Big Data in the Cloud - Montreal April 2015
Big Data in the Cloud - Montreal April 2015
 
iCloud
iCloudiCloud
iCloud
 
LA TUNICA DE COLORES
LA TUNICA DE COLORESLA TUNICA DE COLORES
LA TUNICA DE COLORES
 
Open Scotland - Opening up education across Scotland
Open Scotland - Opening up education across ScotlandOpen Scotland - Opening up education across Scotland
Open Scotland - Opening up education across Scotland
 

Mehr von Xamarin

Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...Xamarin
 
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App CenterXamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App CenterXamarin
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinXamarin
 
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinGet the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinXamarin
 
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePushCreative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePushXamarin
 
Build Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureBuild Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureXamarin
 
Exploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin WorkbooksExploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin WorkbooksXamarin
 
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for XamarinDesktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for XamarinXamarin
 
Developer’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine LearningDeveloper’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine LearningXamarin
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UIXamarin
 
Session 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and ResourcesSession 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and ResourcesXamarin
 
Session 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and ProfitabilitySession 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and ProfitabilityXamarin
 
Session 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile PracticeSession 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile PracticeXamarin
 
Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud Xamarin
 
SkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.FormsSkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.FormsXamarin
 
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureBuilding Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureXamarin
 
Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Xamarin
 
Connected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureConnected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureXamarin
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Xamarin
 
Building Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual StudioBuilding Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual StudioXamarin
 

Mehr von Xamarin (20)

Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...Xamarin University Presents: Building Your First Intelligent App with Xamarin...
Xamarin University Presents: Building Your First Intelligent App with Xamarin...
 
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App CenterXamarin University Presents: Ship Better Apps with Visual Studio App Center
Xamarin University Presents: Ship Better Apps with Visual Studio App Center
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
 
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for XamarinGet the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
Get the Most out of Android 8 Oreo with Visual Studio Tools for Xamarin
 
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePushCreative Hacking: Delivering React Native App A/B Testing Using CodePush
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
 
Build Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureBuild Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft Azure
 
Exploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin WorkbooksExploring UrhoSharp 3D with Xamarin Workbooks
Exploring UrhoSharp 3D with Xamarin Workbooks
 
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for XamarinDesktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
Desktop Developer’s Guide to Mobile with Visual Studio Tools for Xamarin
 
Developer’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine LearningDeveloper’s Intro to Azure Machine Learning
Developer’s Intro to Azure Machine Learning
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UI
 
Session 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and ResourcesSession 4 - Xamarin Partner Program, Events and Resources
Session 4 - Xamarin Partner Program, Events and Resources
 
Session 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and ProfitabilitySession 3 - Driving Mobile Growth and Profitability
Session 3 - Driving Mobile Growth and Profitability
 
Session 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile PracticeSession 2 - Emerging Technologies in your Mobile Practice
Session 2 - Emerging Technologies in your Mobile Practice
 
Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud Session 1 - Transformative Opportunities in Mobile and Cloud
Session 1 - Transformative Opportunities in Mobile and Cloud
 
SkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.FormsSkiaSharp Graphics for Xamarin.Forms
SkiaSharp Graphics for Xamarin.Forms
 
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and AzureBuilding Games for iOS, macOS, and tvOS with Visual Studio and Azure
Building Games for iOS, macOS, and tvOS with Visual Studio and Azure
 
Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017Intro to Xamarin.Forms for Visual Studio 2017
Intro to Xamarin.Forms for Visual Studio 2017
 
Connected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft AzureConnected Mobile Apps with Microsoft Azure
Connected Mobile Apps with Microsoft Azure
 
Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017Introduction to Xamarin for Visual Studio 2017
Introduction to Xamarin for Visual Studio 2017
 
Building Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual StudioBuilding Your First iOS App with Xamarin for Visual Studio
Building Your First iOS App with Xamarin for Visual Studio
 

KĂźrzlich hochgeladen

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vĂĄzquez
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

KĂźrzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

iCloud with MonoTouch

  • 1. Xamarin Seminar 22nd March 2012 Copyright 2012 Š Xamarin Inc. All rights reserved
  • 2. Announcements http://xamarin.com/seminars Xamarin Copyright 2012 Š Xamarin Inc. All rights reserved
  • 3. Agenda iCloud with MonoTouch Craig Dunn Technical Writer Xamarin Documentation Team craig.dunn@xamarin.com Xamarin Copyright 2012 Š Xamarin Inc. All rights reserved
  • 4. Introduction This session discusses Apple’s new iOS5 iCloud functionality and how to implement iCloud features with MonoTouch. We’ll cover: • iCloud Basics & Setup • iCloud Key-Value Storage • iCloud Document Storage • iCloud Backup (iOS Data Storage Guidelines) Xamarin Copyright 2012 Š Xamarin Inc. All rights reserved
  • 5. iCloud Basics (i) • Remote storage & backup • Synchronization of data across devices (iOS & Mac OS X) but NOT conflict resolution • OS process controls sending/receiving Cloud iPhone Local storage storage Local storage iCloud Daemon iCloud Daemon iCloud Daemon Mac Local storage iPad
  • 6. iCloud Basics (ii) • 4 ways to utilize iCloud: • Key-Value Pairs today’s topic • UIDocument • CoreData another • Individual les/folders time...
  • 7. iCloud Setup (i) • App ID & Provisioning Prole (developer.apple.com) • grants iCloud support (tick the box!) • linked to your TeamID and the BundleID • Entitlements.plist (in your project) • specify TeamID & BundleID • use these keys: com.apple.developer.ubiquity-kvstore-identifier com.apple.developer.ubiquity-container-identifiers
  • 8.
  • 9. iCloud Setup (iii) • MonoDevelop Entitlements UI with placeholder expansion: • $(TeamPrexIdentier) automatically added • $(CFBundleIdentier) for the default ubiquity-identier han it E asier t ith l ooks, w lop! Mono Deve
  • 10. iCloud Setup (iv) • Don’t forget the devices! • Same AppleID on each device
  • 11. Key-Value Pairs (i) • Similar to NSUserDefaults • Simple types only (whatever works in a plist): text, number, date • Limited size: • 64Kb total • 64Kb max per key too • Recommendation: use NSUserDefaults and ‘shadow’ with iCloud Key-Value pairs
  • 12. Key-Value Pairs (ii) Example creates a ‘key’ for each device, plus a Shared one.
  • 13. Key-Value Pairs (iii) • SetString • GetString • Synchronize() returns false if no iCloud OR if no updates are required • Your app should run even if the Key-Values are empty! (sounds obvious, but...)
  • 14. Key-Value Pairs (iv) • Change Notications Register for notication ServerChange InitialSyncChange QuotaViolationChange Tells us which keys NSArray of IntPtrs have changed values Loop through the keys, get the new values and do something!
  • 15. Files in the Cloud • NSFileCoordinator & NSFilePresenter work with the iCloud to prevent contention on the local copy • UIDocument hides that complexity from you! aka UbiquityContainer Cloud storage Presenter / Coordinator Local Presenter / Coordinator Local storage storage iPhone iCloud Daemon iCloud Daemon Mac Presenter / Coordinator iCloud Daemon or just use Local UIDocument! storage iPad
  • 16. UbiquityContainer Ru ki Bloc backg a all! ng c round n on thread! • NSFileManager.DefaultManager.GetUrlForUbiquityContainer() • /private/var/mobile/Library/Mobile%20Documents/ AAA7MMJKYN~com~xamarin~samples~taskcloud/ Documents/ (user-visible in Settings) <your other stuff> • Not to be confused with your app’s home directory • /private/var/mobile/Applications/42871799- F2CD-455B-9353-749B15C8AA76/ TaskCloud.app (app bundle) Documents/ (user-visible in iTunes) Library/ <your other stuff>
  • 17. UIDocument (spoilers) • Where are iCloud documents stored? UbiquityContainer Asyn c • How do you create a UIDoc? UIDoc.Save(ForCreating) Asyn c • How do you open one? UIDoc.Open() Asyn • How are changes applied? your model on the UIDoc) c (to • How do you save it again? UpdateChangeCount() UIDoc. • What if it changes elsewhere? for notication... Listen Asyn c • How do you enumerate NSMetadataQuery() Asyn c UIDocs? Asyn c
  • 19. Finding UbiquityContainer This one line is key to getting Asyn c iCloud working! Do this in FinishedLoading. Apple also recommends re-checking each time the app comes to the foreground.
  • 20. Subclassing UIDocument • Override the ‘read’ and ‘write’ methods: • Actually called LoadFromContents() and ContentsForType() • iCloud takes care of when they’re called and manages contention at the le system level. • You NEVER read/write the lesystem directly! • Save(CompletionHandler) As ync hro no • Open(CompletionHandler) us! • UpdateChangeCount
  • 21. Subclassing UIDocument url to UbiquityContainer location default value ‘Model’ can be as simple or complex as you like aka ‘Open’ So we can respond to this data changes if we want aka ‘Save’ accesses the model and sends to lesystem
  • 22. Create a UIDoc Put user-generated les in the /Documents/ directory Has the ‘(default text)’ set Save happens Asyn asynchronously, the c completion handler runs when it is done • You could also use NSFileManager.DefaultManager.SetUbiquitous() to move an existing le from your home directory to the UbiquityContainer
  • 23. Open UIDoc Open specic lename from the /Documents/ directory Asyn c Might need to be run on Main thread
  • 24. Changes Applied & Saved UpdateChangeCount() is Update the model with all that is required to the edited text signal to iCloud that the le should be saved* * You can implement full undo/redo instead of UIDocumentChangeKind.Done
  • 25. Changes Elsewhere Listen for notication sent by the UIDocument subclass when it is changed When that notication occurs, we are grabbing the updated text and assigning it to the UITextView * * In a real app, you would probably want to do some conflict resolution instead...
  • 26. Enumerate UIDocs (i) CloudUIDoc example Looking for a single, specic lename Special Predicate syntax (monkeyDocFilename) TaskCloud example (just to show a different query) Looking for all Special Predicate syntax *.task les queryDidFinishGathering on next slide...
  • 27. Enumerate UIDocs (ii) When the NSMetadataQuery is done, we stop it (it could keep running/ monitoring) and remove our listener We expect only one le in the example app; get its “ItemURL” then create and open the document from that location • Metadata sync’s faster, so other devices will learn if a particular le has been created (even though they don’t know the contents)
  • 28. Debugging Tips (i) • The /Documents/ directory can be managed by the user (and you, for testing)
  • 29. Debugging Tips (ii) • Check your iCloud-linked Mac, sync’d les will be there if everything is working correctly /Users/<you>/Library/Mobile Documents/<TeamId><BundleId>/Documents
  • 30. iOS Data Storage Guidelines (for iCloud) • Only documents that are user-generated should go into /Documents/ • Data that can be re-created should go into /Library/Caches/ • Temp data should be in /tmp/ • Use the “do not backup” attribute to prevent ANY les being backed-up to iCloud
  • 33. References (i) Introduction to iOS 5 (currently being updated) http://docs.xamarin.com/ios/tutorials/Introduction_to_iOS_5 What’s New in iOS https://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/ Introduction/Introduction.html TaskCloud - iCloud UIDocument sample http://conceptdev.blogspot.com.au/2012/03/icloud-uidocument-sample-taskcloud.html https://github.com/conceptdev/taskcloud chat2self - iCloud Key-Value sample http://conceptdev.blogspot.com.au/2012/02/icloud-key-value-example-chat2self.html https://github.com/conceptdev/Chat2self iOS Data Storage Guidelines https://developer.apple.com/icloud/documentation/data-storage/ Xamarin Copyright 2012 Š Xamarin Inc. All rights reserved
  • 34. References (ii) NSFilePresenter Protocol Reference http://developer.apple.com/library/mac/#documentation/Foundation/Reference/ NSFilePresenter_protocol/Reference/Reference.html NSFileCoordinator Class Reference http://developer.apple.com/library/mac/#documentation/Foundation/Reference/ NSFileCoordinator_class/Reference/Reference.html iCloud Developer Documentation https://developer.apple.com/icloud/documentation/ Xamarin Copyright 2012 Š Xamarin Inc. All rights reserved
  • 35. Xamarin Seminar Please give us your feedback http://bit.ly/xamfeedback Follow us on Twitter @XamarinHQ 22nd March 2012 Copyright 2012 Š Xamarin Inc. All rights reserved

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n