iDev

Parse SDK 강좌 - 1 - Parse SDK 간단한 소개

KraZYeom 2012. 5. 8. 19:06
반응형

Parse SDK를 이용하면 데이터 저장, 유저 관리(twitter, Facebook 로그인), Push, Social, File, Location 정보를 손쉽게 관리 할 수 있습니다. iOS 뿐만 아니라 Android SDK도 제공합니다. 


아래 예제는 parse.com에서 제공하는 기본 api 예제입니다. KVC를 통해서 손쉽게 데이터를 사용 할 수 있습니다. 


저같은놈 처럼 시간도 없으면서 서버관리 등등을 혼자 하기 힘들고 모든것을 혼자 구현하기 힘들때 사용하기 참 좋은 것 같습니다. 


유료 기능과 똑같은 기능을 무료로 사용가능하며, 유료일경우에는 api request 횟수, push 사용횟수, 데이터 저장 공간이 늘어 납니다. https://parse.com/plans  참조


parse.com 에 있는 문서를 번역 & 수정해서 강좌를 써볼까 합니다. 그냥 제가 사용하는 목적 겸해서요.


Data 

// Create a new Parse object
PFObject *post = [PFObject objectWithClassName:@"Post"];
[post setObject:@"Hello World" forKey:@"title"];

// Save it to Parse 

[post saveInBackground];


Push

// Subscribe to a push channel                                
[PFPush subscribeToChannelInBackground:@"ipad_news"];

// Push to the channel from the client
push.sendInBackground();
[PFPush sendPushMessageToChannelInBackground:@"ipad_news" 

withMessage:@"The new iPad has been released!"];


User

// Initialize the user object

PFUser *user = [PFUser user];
user.username = @"mario";
user.password = @"mushroomkingdom";

[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        // Hooray! Let them use the app now.
    } else {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        // Show the errorString somewhere and let the user try again.
    }
}];


Social 

[PFFacebookUtils logInWithPermissions:permissions block:^(PFUser *user, NSError *error) {
    if (!user) {
        NSLog(@"Uh oh. The user cancelled the Facebook login.");
    } else if (user.isNew) {
        NSLog(@"User signed up and logged in through Facebook!");
    } else {
        NSLog(@"User logged in through Facebook!");
    

}];


Location 

PFGeoPoint *point = [PFGeoPoint geoPointWithLatitude:40.0 longitude:-30.0];
[placeObject setObject:point forKey:@"location"]; 

[placeObject saveInBackground];


File

NSData *data = [@"Working at Parse is great!" dataUsingEncoding:NSUTF8StringEncoding];
PFFile *file = [PFFile fileWithName:@"resume.txt" data:data]; 

[file saveInBackground];


반응형