2014년 11월 9일 일요일

아이폰 - 아이클라우드(iCloud) 간단한 데모 코드 입니다.

아이클라우드(iCloud) 간단한 데모 코드 입니다. 조회 : 79
나의 폴더 > 아이폰 | 2012-12-13 (Thu) 12:44http://blog.dreamwiz.com/papasmf1/13911329
아이클라우드(iCloud) 간단한 데모 코드 입니다.
복잡하게 많은 기능들을 제공하지만 아래의 코드에서는 키-밸류 기반으로 간단한 동기화 데모를
보실 수 있습니다.

//
//  ViewController.h
//  DemoiCloudKey
//
//  Created by kim jong duk on 12. 9. 7..
//  Copyright (c) 2012 kim jong duk. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    UITextField *textField;
    NSUbiquitousKeyValueStore *keyStore;
}

@property (strongnonatomicIBOutlet UITextField *textField;
-(IBAction)saveKey;

@end

//
//  ViewController.m
//  DemoiCloudKey
//
//  Created by kim jong duk on 12. 9. 7..
//  Copyright (c) 2012 kim jong duk. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize textField;

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    keyStore = [[NSUbiquitousKeyValueStore allocinit];
    
    NSString *storedString = [keyStore stringForKey:@"MyString"];
    if(storedString != nil) {
        textField.text = storedString;
    }
    
    [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(ubiquitousKeyValueStoreDidChange:)name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification object:keyStore];
    
}

-(void)ubiquitousKeyValueStoreDidChange:(NSNotification *)notification
{
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Change detected" message:@"iCloud key-value store change detected" delegate:nilcancelButtonTitle:@"OK" otherButtonTitles:nilnil];
    [alert show];
    textField.text = [keyStore stringForKey:@"MyString"];
}

-(void)saveKey
{
    [keyStore setString:textField.text forKey:@"MyString"];
    [keyStore synchronize]; 
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end



Xcode 4.5에서 Single-View Application으로 생성해서 프로젝트 => 타겟에서 Entitlements 메뉴에서 위의 그림처럼 아이클라우드를 사용하도록 체크하면 됩니다. 

댓글 없음:

댓글 쓰기

참고: 블로그의 회원만 댓글을 작성할 수 있습니다.

5월 14일 새벽에 chatGPT 4o가 발표되었습니다. 옵티마이즈, 옴니라는 의미인데 실시간 통역, 다자간 회의, 멀티모달 기능의 강화등이 보이네요.

  초격차로 OpenAI진영이 다시 앞서가는 모양을 보여주고 있습니다. 저도 새벽에 일어나자 마자 올라온 영상들과 글을 정리하고 있습니다. ㅎㅎ 영화 HER의 사진이 새벽에 많이 올라왔었는데 저도 안본 영화입니다. 주말에 한번 봐야 할 것 같습니다....