Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

[Osxdev]7.handoff

1,086 views

Published on

OSXDEV 오픈세미나 - WWDC 따라잡기

Published in: Technology
  • Be the first to comment

[Osxdev]7.handoff

  1. 1. 경험의 연속? Handoff idiel@osxdev.org
  2. 2. Agenda • 나는 왜 짤방경쟁에 참여하지 않았는가 • Handoff가 뭔가요? • 어떻게해요? • 되긴 하는겁니까? • 시간이 남으면…
  3. 3. 미안하다
  4. 4. Continuity • Handoff • Phone call / Messages • Hotspot
  5. 5. Handoff
  6. 6. Handoff
  7. 7. Handoff
  8. 8. 지금은 어떻게? • 데이터 동기화 • iCloud • 서드파티 클라우드 • 커스텀 클라우드 • URL, AppLink
  9. 9. iCloud
  10. 10. 써드파티 솔루션 • DropBox • Box • N드라이브 • 다음 클라우드 • Google Drive • One Drive • …
  11. 11. 직접 구현
  12. 12. Missing Link
  13. 13. Demo • Mail • Safari
  14. 14. Handoff Interactions
  15. 15. Handoff • 사용자 요구사항 • 근접 위치 기반 • Bluetooth LE • 동일한 iCloud 계정 • 개발 요구사항 • 동일한 개발자 인증 • 액티비티 타입
  16. 16. 사용자 활동 • 사용자는 내 앱에서 무엇을 하는가? • 메일을 읽는다/작성한다/목록에서 선택한다 • 웹사이트를 브라우징한다 • 글을 작성한다 • MCArmory • 장비를 고른다
  17. 17. NSUserActivity • 클래스 하나 • activityType • userInfo • 메서드 • becomeCurrent • invalidate
  18. 18. NSUserActivity NSUserActivity* myActivity = [[NSUserActivity alloc] initWithActivityType:@"com.myCompany.myBrowser.browsing"]; myActivity.userInfo = @{ ... }; myActivity.title = @"Browsing"; [myActivity becomeCurrent]; • userInfo • NSArray, NSData, NSDate, NSDictionary, NSNull, NSNumber, NSSet, NSString, NSUUID, NSURL
  19. 19. NSUserActivity • activityType • 역 도메인명 + 액티비티 명 • “org.osxdev.demoApp.demo-began” • 동일한 개발자 • 액티비티 생성 / 액티비티 소비 다를 수 있음
  20. 20. 액티비티 만들기 • NSDocument, UIDocument, NSResponder UIResponder • 문서기반 • userActivity 자동 생성 (iCloud) • 문서/리스폰더 기반 • becomeCurrent • invalidate @property (strong) NSUserActivity *userActivity;
  21. 21. 액티비티 만들기 • 문서기반
  22. 22. 액티비티 만들기 NSUserActivity *currentActivity = [self userActivity]; NSString *bundleName = [[NSBundle mainBundle] bundleIdentifier]; NSString *myActivityType = [bundleName stringByAppendingString:@".selected-list"]; if(![[currentActivity activityType] isEqualToString:myActivityType]) { [currentActivity invalidate]; currentActivity = [[NSUserActivity alloc] initWithActivityType:myActivityType]; [currentActivity setDelegate:self]; [currentActivity setNeedsSave:YES]; [self setUserActivity:currentActivity]; } else { [currentActivity setNeedsSave:YES]; }
  23. 23. • Mail.app Info.plist
  24. 24. • Safari.app Info.plist
  25. 25. 액티비티 처리하기 • AppDelegate (NS/UIApplicationDelegate) - (BOOL)application:(NSApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType - (BOOL)application:(NSApplication *)application continueUserActivity: (NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler - (void)application:(NSApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error - (void)application:(NSApplication *)application didUpdateUserActivity: (NSUserActivity *)userActivity
  26. 26. 액티비티 처리하기 - (BOOL)application:(NS/UIApplication *)application
 willContinueUserActivityWithType:(NSString *)activityType {
 if ([activityType isEqual:@“com.company.viewing-message”]) {
 id vc = [[MessageViewController alloc] init];
 vc.showLoadingIndicator = YES; [self showMessageViewController:vc]; return YES;
 }
 return NO; }
  27. 27. 액티비티 처리하기 - (BOOL)application:continueUserActivity:restorationHandler: {
 NSString *activityType = activity.activityType; if ([activityType isEqual:@“com.company.viewing-message”]) { id vc = [[MessageViewController alloc] init];
 ... restorationHandler(@[vc]); return YES;
 } return NO; } - (void)restoreUserActivityState:(NSUserActivity *)activity { [super restoreUserActivityState:activity]; [self setMessageID:activity.userInfo[@“messageID”]];
 ...
 id cvc = [[ConversationViewController alloc] init];
 ...
 [cvc restoreUserActivityState:activity];
 }
  28. 28. 액티비티 처리하기 • 복원 - (void)restoreUserActivityState:(NSUserActivity *)activity - (void)restoreUserActivityState:(NSUserActivity *)activity { [super restoreUserActivityState:activity]; NSString *version = activity.userInfo[@“handoffVersion”] BOOL isOldVersion = [self isOldVersion:version]; NSString *recipientKey = isOldVersion ? @“to” : @“rcptID”;
 self.recipient = activity.userInfo[recipientKey];
 [self updateRecipientImage]; }
  29. 29. 액티비티 처리하기 • NSUserActivityDelegate - (void)userActivityWasContinued:(NSUserActivity *)userActivity - (void)userActivityWillSave:(NSUserActivity *)userActivity - (void)userActivity:(NSUserActivity *)userActivity
 didReceiveInputStream:(NSInputStream *)inputStream
         outputStream:(NSOutputStream *)outputStream
  30. 30. 데모
  31. 31. 버저닝 - (void)restoreUserActivityState:(NSUserActivity *)activity { [super restoreUserActivityState:activity]; NSString *version = activity.userInfo[@“handoffVersion”] BOOL isOldVersion = [self isOldVersion:version]; NSString *recipientKey = isOldVersion ? @“to” : @“rcptID”;
 self.recipient = activity.userInfo[recipientKey];
 [self updateRecipientImage]; } - (void)application:(NS/UIApplication *)application 
 didUpdateUserActivity:(NSUserActivity *)userActivity { [userActivity addUserInfoEntriesFromDictionary:@{@“handoffVersion”: @“2.0”,}];
 }
  32. 32. 웹사이트 핸드오프 • App to Web • userActivity.webpageURL
  33. 33. 웹사이트 핸드오프 • Web to App • activityType: “url” (NSUserActivityTypeBrowsingWeb) • com.apple.developer.associated-domains entitlement • Signed web credentials in JSON file > https:// example.com/apple-app-site-association
  34. 34. Continuation Stream activity.supportsContinuationStreams = YES; - (BOOL)application:(UIApplication *)application continueUserActivity: (NSUserActivity *)userActivity restorationHandler: (void(^)(NSArray *restorableObjects))restorationHandler { [userActivity getContinuationStreamsWithCompletionHandler:^( NSInputStream *inputStream, NSOutputStream *outputStream, NSError *error) { // Do something with the streams }]; return YES; }
  35. 35. 주의사항 • 전송 데이터(userInfo)는 최소화 • 큰 데이터가 필요하다면 Continuation Stream 사용 • 버전, 플랫폼, Mac/iOS 앱 차이 • com.<company>.<app>.<activity type> • needSave / userActivityWillSave: 사용 • application:willContinueUserActivityWithType: 구현
  36. 36. Q&A • Handoff Programming Guide • https://developer.apple.com/library/prerelease/ ios/documentation/UserExperience/Conceptual/ Handoff/Introduction/Introduction.html • WWDC 2014 Videos • https://developer.apple.com/videos/wwdc/2014/

×