페이스 북

필요한 프레임워크

Accounts.framework

Social.framework

Adsupport.framework

FacebookSDK.framework

번들 파일도 추가함 : FacebookSDKResources.bundle      FBUserSettingsViewResources.bundle

appdelete.m파일/////////facebook연동시 필요한 부분////////////
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    [FBSession.activeSession handleDidBecomeActive];
}

- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [FBSession.activeSession handleOpenURL:url];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    [FBSession.activeSession close];
}
/////////facebook연동시 필요한 부분////////////

구현할 파일에 가서

#import <FacebookSDK/FacebookSDK.h>

<FBLoginViewDelegate>

//////소스 구현 부분/////

UIImage *img = picImg.image;
        
        // if it is available to us, we will post using the native dialog
        BOOL displayedNativeDialog = [FBNativeDialogs presentShareDialogModallyFrom:self
                                                                        initialText:contentText.text
                                                                              image:img
                                                                                url:nil
                                                                            handler:nil];
        
        NSMutableDictionary * postParams =  [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                             @"photo description", @"name",
                                             nil];
        [postParams setObject:picImg.image forKey:@"picture"];
        [postParams setObject:contentText.text forKey:@"message"];
        NSLog(@"param = %@", postParams);
        
        if (!displayedNativeDialog) {
            [self performPublishAction:^{
                
                [FBRequestConnection startWithGraphPath:@"me/photos" parameters:postParams HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                    NSLog(@"error = %@", error);
                }];
                
            }];
        }

//////소스 구현 부분/////

target에서 info 부분 수정

FacebookAppID ---> 311092382324995(앱id)

url types ----> fd311092382324995(앞에 fd붙이고 앱id)

////////////////////////////////////////////////

트위터 연동

필요한 프레임워크

Twitter.framework

MobileCoreServices.framework

#import <Twitter/TWTweetComposeViewController.h>
#import <MobileCoreServices/MobileCoreServices.h>

TWTweetComposeViewController *tweetView;

@property (nonatomic, strong) TWTweetComposeViewController *tweetView;

구현할 소스 부분/////////////////////////

if ([TWTweetComposeViewController canSendTweet]) {
           
            TWTweetComposeViewController *twtCntrlr = [[TWTweetComposeViewController alloc] init];
//            [twtCntrlr addURL:[NSURL URLWithString:_shareURL]];
            [twtCntrlr addImage:picImg.image];
            [twtCntrlr setInitialText:contentText.text];
           
            [self presentModalViewController:twtCntrlr animated:YES];
        }

/////////////////////////

      
Posted by k_ben