iOS5 NewStuff

1,611 views
1,574 views

Published on

'Development using iOS5 NewStuff' keynote for #IDOC2012. Bandung, 18th February 2012.
- iCloud Storage
- CoreImage
- NewsStand
Demo and sample code : https://github.com/DeenNa

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,611
On SlideShare
0
From Embeds
0
Number of Embeds
463
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • iOS5 NewStuff

    1. 1. iOS 5 New Stuff R.Ayu Maulidina.I.
    2. 2. Over 200 new user features
    3. 3. SDK & Development tools?over 1,500 new APIs and powerful new development tools
    4. 4. iCloud Storage API Apa itu iCloud? - Sync service - Transfers user data between devices - Runs in background - Per-app sandboxing (as usual) Keuntungannya Apa ?- Gak perlu ‘sync server’ sendiri.- Gak perlu ‘network protocol’ sendiri.- Gak perlu bayar ‘storage/bandwidth’ sendiri. Intinya sih gak perlu repot-repot.
    5. 5. Konsep dan Ketentuan iCloud UbiquitousSuatu keadaan yang memungkinkan manusia untuk berinteraksi dengan ‘komputer’ dimana saja, kapan saja dan bagaimana saja.
    6. 6. Sinkronisasi BackgroundUbiquity daemon, ubdSaat anda menyimpan perubahan, ubd mengirimkannya pada ‘cloud’ubd akan mengunduhnya dari iCloudDimana itu berarti....
    7. 7. Data anda dapat berubah tanpa peringatan..
    8. 8. iCloud ContainersLokasi untuk data aplikasi anda berada di iCloudSetiap pengaktifan iCloud pada aplikasi setidaknya hanyamemiliki satu tempat.Kontainer sesuai dengan direktori yang kita buat
    9. 9. File CoordinatorData dapat diubah oleh aplikasi anda atau oleh ubd(Ubiquity Daemon)Membutuhkan ‘reader/writer lock’ untuk akses koordinasiMenggunakan ‘NSFileCoordinator’ saat menulis ataumembacanya
    10. 10. File PresenterDisertakan juga pada file koordinatorMenerapkan ‘NSFilePresenter’ agar mendapatpemberitahuan akan adanya perubahanSaat file koordinator membuat perubahan, maka ‘filepresenter’ ini akan dipanggil.
    11. 11. iCloud APIsKey-value storeCore DataDocument
    12. 12. Gimana cara mengaktifkan iCloud ?App ID on Provisioning Portal --->developer.apple.com/ios/ ---> app IDs
    13. 13. Konfigurasi app ID
    14. 14. Peringatan!
    15. 15. Configuration name for identifier, entitlements file, iCloud key-value store, containers and keychain access groups.
    16. 16. Entitlements Setting
    17. 17. Ubiquitous Documents
    18. 18. UIDocumentAsynchronous block-based reading and writingAuto-savingFlat file and file packages
    19. 19. UIDocument with iCloudActs as a file coordinator and presenterMendeteksi conflicts- Notifications- API to help resolve
    20. 20. UIDocument Concepts Outside the (sand)box- iCloud documents are not located in your app sandbox- Located in your iCloud container- Create the document in the sandbox- Move it to iCloud
    21. 21. Document StateUIDocumentStateNormalUIDocumentStateClosedUIDocumentStateInConflictUIDocumentStateSavingErrorUIDocumentStateEditingDisabledUIDocumentStateChangedNotification
    22. 22. Demo Code: CloudNotes
    23. 23. Subclassing UIDocument@interface NoteDocument : UIDocument@property (strong, readwrite) NSString *documentText;@end
    24. 24. Subclassing UIDocument- (BOOL)loadFromContents:(id)contents ofType:(NSString*)typeName error:(NSError *__autoreleasing *)outError;- (id)contentsForType:(NSString *)typeName error:(NSError*__autoreleasing *)outError;
    25. 25. - (BOOL)loadFromContents:(id)contents ofType:(NSString*)typeName error:(NSError *__autoreleasing *)outError{ NSString *text = nil; if ([contents length] > 0) { text = [[NSString alloc] initWithBytes:[contents bytes] length:[contents length] encoding:NSUTF8StringEncoding]; } else { text = @""; }}[self setDocumentText:text];return YES;
    26. 26. - (id)contentsForType:(NSString *)typeName error:(NSError*__autoreleasing *)outError { if ([[self documentText] length] == 0) { [self setDocumentText:@"New note"]; } return [NSData dataWithBytes:[[self documentText] UTF8String] length:[[self documentText] length]];}
    27. 27. Creating a NoteDocument
    28. 28. - (NSURL*)ubiquitousDocumentsDirectoryURL{ NSURL *ubiquitousContainerURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; NSURL *ubiquitousDocumentsURL = [ubiquitousContainerURL URLByAppendingPathComponent:@"Documents"]; if (ubiquitousDocumentsURL != nil) { if (![[NSFileManager defaultManager] fileExistsAtPath:[ubiquitousDocumentsURL path]]) { NSError *createDirectoryError = nil; BOOL created = [[NSFileManager defaultManager] createDirectoryAtURL:ubiquitousDocumentsURL withIntermediateDirectories:YES attributes:0 error:&createDirectoryError]; if (!created) { NSLog(@"Error creating directory at %@: %@", ubiquitousDocumentsURL, createDirectoryError); } } } else { NSLog(@"Error getting ubiquitous container URL"); } return ubiquitousDocumentsURL;}
    29. 29. - (NSURL*)ubiquitousDocumentsDirectoryURL{ NSURL *ubiquitousContainerURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; NSURL *ubiquitousDocumentsURL = [ubiquitousContainerURL URLByAppendingPathComponent:@"Documents"]; if (ubiquitousDocumentsURL != nil) { if (![[NSFileManager defaultManager] fileExistsAtPath:[ubiquitousDocumentsURL path]]) { NSError *createDirectoryError = nil; BOOL created = [[NSFileManager defaultManager] createDirectoryAtURL:ubiquitousDocumentsURL withIntermediateDirectories:YES attributes:0 error:&createDirectoryError]; if (!created) { NSLog(@"Error creating directory at %@: %@", ubiquitousDocumentsURL, createDirectoryError); } } } else { NSLog(@"Error getting ubiquitous container URL"); } return ubiquitousDocumentsURL;}
    30. 30. - (void)createFileNamed:(NSString *)filename{ NSURL *localFileURL = [[self localDocumentsDirectoryURL] URLByAppendingPathComponent:filename]; NoteDocument *newDocument = [[NoteDocument alloc] initWithFileURL:localFileURL]; [newDocument saveToURL:localFileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (success) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURL *destinationURL = [[self ubiquitousDocumentsDirectoryURL] URLByAppendingPathComponent:filename]; NSError *moveToCloudError = nil; BOOL success = [[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:[newDocument fileURL] destinationURL:destinationURL error:&moveToCloudError]; if (!success) { NSLog(@"Error moving to iCloud: %@", moveToCloudError); } }); } }];}
    31. 31. - (void)createFileNamed:(NSString *)filename{ NSURL *localFileURL = [[self localDocumentsDirectoryURL] URLByAppendingPathComponent:filename]; NoteDocument *newDocument = [[NoteDocument alloc] initWithFileURL:localFileURL]; [newDocument saveToURL:localFileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (success) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURL *destinationURL = [[self ubiquitousDocumentsDirectoryURL] URLByAppendingPathComponent:filename]; NSError *moveToCloudError = nil; BOOL success = [[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:[newDocument fileURL] destinationURL:destinationURL error:&moveToCloudError]; if (!success) { NSLog(@"Error moving to iCloud: %@", moveToCloudError); } }); } }];}
    32. 32. - (void)createFileNamed:(NSString *)filename{ NSURL *localFileURL = [[self localDocumentsDirectoryURL] URLByAppendingPathComponent:filename]; NoteDocument *newDocument = [[NoteDocument alloc] initWithFileURL:localFileURL]; [newDocument saveToURL:localFileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (success) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSURL *destinationURL = [[self ubiquitousDocumentsDirectoryURL] URLByAppendingPathComponent:filename]; NSError *moveToCloudError = nil; BOOL success = [[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:[newDocument fileURL] destinationURL:destinationURL error:&moveToCloudError]; if (!success) { NSLog(@"Error moving to iCloud: %@", moveToCloudError); } }); } }];}
    33. 33. Create new document
    34. 34. Core Image
    35. 35. image processing technologymemungkinkan proses mendekati real-timemenyediakan akses untuk ‘built-in image filters’ padavideo and gambarmenyediakan juga fitur untuk membuat ‘custom filters’
    36. 36. Class References1.CIColor2.CIContext3.CIDetector4.CIFaceFeature5.CIFeature6.CIFilter7.CIImage8.CIVector
    37. 37. Face Detection
    38. 38. CIFaceFeature Facial Features•   hasLeftEyePosition  property•   hasRightEyePosition  property•   hasMouthPosition  property•   leftEyePosition  property•   rightEyePosition  property•   mouthPosition  property
    39. 39. Demo Code: Easy Face Detection
    40. 40. // well iterate through every detected face. CIFaceFeature provides us // with the width for the entire face, and the coordinates of each eye // and the mouth if detected. Also provided are BOOLs for the eyes and // mouth so we can check if they already exist. for(CIFaceFeature* faceFeature in features) { // get the width of the face CGFloat faceWidth = faceFeature.bounds.size.width; // create a UIView using the bounds of the face UIView* faceView = [[UIView alloc] initWithFrame:faceFeature.bounds]; // add a border around the newly created UIView faceView.layer.borderWidth = 1; faceView.layer.borderColor = [[UIColor redColor] CGColor]; // add the new view to create a box around the face [self.window addSubview:faceView]; if(faceFeature.hasLeftEyePosition) { // create a UIView with a size based on the width of the face UIView* leftEyeView = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.leftEyePosition.x-faceWidth*0.15,faceFeature.leftEyePosition.y-faceWidth*0.15, faceWidth*0.3, faceWidth*0.3)]; // change the background color of the eye view [leftEyeView setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.3]]; // set the position of the leftEyeView based on the face [leftEyeView setCenter:faceFeature.leftEyePosition]; // round the corners leftEyeView.layer.cornerRadius = faceWidth*0.15; // add the view to the window [self.window addSubview:leftEyeView]; } if(faceFeature.hasRightEyePosition) { // create a UIView with a size based on the width of the face UIView* leftEye = [[UIView alloc] initWithFrame:CGRectMake(faceFeature.rightEyePosition.x-faceWidth*0.15,faceFeature.rightEyePosition.y-faceWidth*0.15, faceWidth*0.3, faceWidth*0.3)]; // change the background color of the eye view [leftEye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.3]]; // set the position of the rightEyeView based on the face [leftEye setCenter:faceFeature.rightEyePosition]; // round the corners leftEye.layer.cornerRadius = faceWidth*0.15; // add the new view to the window [self.window addSubview:leftEye]; }
    41. 41. Detector Option KeysKeys used in the options dictionary to configure a detector.Detector Accuracy OptionsNSString* const CIDetectorAccuracyLow;NSString* const CIDetectorAccuracyHigh;- CIDetectorAccuracyLowIndicates that the detector should choose techniques that are lower in accuracy, but can beprocessed more quickly.- CIDetectorAccuracyHighIndicates that the detector should choose techniques that are higher in accuracy, even if itrequires more processing time.
    42. 42. Real-time Example by Erica Sadun
    43. 43. Newsstand
    44. 44. Newsstand for developerSimpel dan mudah digunakan untuk konten majalahdan surat kabarTermasuk gratis berlangganan untuk pengguna iPhone,iPod touch dan iPadMenerbitkan edisi terbaru majalah dan surat kabarlangsung menggunakan Newsstand kit dan Store kitframework
    45. 45. NewsstandKitPush notificationupdatesContent organizationBackgrounddownloads
    46. 46. Menampilkan pada NewsstandMenjadikan Newsstand app Menambahkan satu key dalam file Info.plist <key>UINewsstandApp</key> <true/> Yak jadilah Newsstand app! Tapi masih butuh icon nih.
    47. 47. Menampilkan pada NewsstandStandard icon specification Standard icon specification • Top-level key in your Info.plist with an array of image name <key>CFBundleIconFiles</key> Key pada level paling atas di file <array> Info.plist berisi array nama dari image ! <string>Icon.png</string> ! <string>Icon@2x.png</string> ... </array>
    48. 48. Menampilkan pada NewsstandUpdating your Info.plist Updating your Info.plist <key>CFBundleIcons</key> New top-level key <dict> <key>CFBundlePrimaryIcon</key> Icon style key <dict> <key>CFBundleIconFiles</key> <array> Existing CFBundleIconFiles <string>Icon.png</string> <string>Icon@2x.png</string> </array> </dict> </dict>
    49. 49. Newsstand info-plist
    50. 50. Handling UpdatesRetrieving and presenting content Retrieving and presenting content Informing theInforming the app • app INFORMING • Organizing issues Organizing issues content • Downloading UPDATING ORGANIZING • Updating your icon Downloading content DOWNLOADING Updating your icon 27
    51. 51. Informing the AppPush notifications
    52. 52. Informing the AppNewsstand Push Notifications
    53. 53. Informing the AppNewsstand Push Notifications
    54. 54. Organizing IssuesUsing NKLibrary • Provides persistent state for : ■ Available issues ■ Ongoing downloads ■ Issue being read!• Organizes issues ■ Uses app’s Caches directory ■ Improves resource management
    55. 55. Organizing IssuesNKIssues • Creating issues ■ Penamaan yang unik ■ Tanggal publikasi NKIssue *myIssue = [myLibrary addIssueWithName:issueName date:issueDate]; ■ Mengolah repository di dalam ‘library’ NSURL *baseURL = [myIssue contentURL];• Setting the current issue[myLibrary setCurrentlyReadingIssue:myIssue];
    56. 56. Handling UpdatesDownloading contentDownloading ContentNKAssetDownload • Handles data transfer ■ Keeps going• Uses NSURLConnectionDelegate• Wake for critical events newsstand-content• Wi-Fi only in background
    57. 57. Downloading ContentSetup NSArray *itemsToDownload = !! query server for list of assets for (item in itemsToDownload) { NSURLRequest *downloadRequest = [item URLRequest]; NKAssetDownload *asset = [issue addAssetWithRequest:downloadRequest]; NSURLConnection *connection = [asset downloadWithDelegate:myDelegate]; }}
    58. 58. Downloading ContentNSURLConnectionDownloadDelegate [asset downloadWithDelegate:myDelegate];• Implements NSURLConnectionDelegate ■ Status ■ Authentication ■ Completion• Modifications-connection:didWriteData:totalBytesWritten:expectedTotalBytesWritten:-connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytesWritten:-connectionDidFinishDownloading:destinationURL: ---> required
    59. 59. Updating Your Newsstand Icon Update your icon and badge Simple! Update Icon-[UIApplication setNewsstandIconImage:(UIImage*)]• Bisa digunakan saat berjalan di background, jadi bisa diupdate kapanpun jika konten sudah siap. Update Badge• Uses existing badge API-[UIApplication setApplicationIconBadgeNumber:(NSInteger)]
    60. 60. DemoCreating a Newsstand App
    61. 61. See you...

    ×