2012-09-24 40 views
2

我想知道是否有可能使用SLComposeViewController發佈的東西在用戶的Facebook牆上,但沒有顯示共享表/對話框?張貼到Facebook沒有對話框ios 6

以下是我使用的代碼:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { 

     SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 

     SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
      if (result == SLComposeViewControllerResultCancelled) { 

       NSLog(@"Cancelled"); 

      } else 

      { 
       NSLog(@"Done"); 
      } 

      [controller dismissViewControllerAnimated:YES completion:Nil]; 
     }; 
     controller.completionHandler =myBlock; 

     [controller setInitialText:eventInfoToFacebook]; 

     [self presentViewController:controller animated:YES completion:Nil]; 

    } 

在此先感謝。

+0

您是否需要使用Apple的框架? – leo

回答

-1

這是可能的facebook-ios-sdk 3.0。 here

我正在與這段代碼分享。

[FBRequestConnection startWithGraphPath:@"me/feed" 
          parameters:params 
          HTTPMethod:@"POST" 
         completionHandler:^(FBRequestConnection *connection, 
              NSDictionary * result, 
              NSError *error) { 
          if (error) { 
           NSLog(@"Error: %@", [error localizedDescription]); 
          } else { 

           } 
         }]; 

我打電話時,用戶點擊分享按鈕,並有一個與它直接發佈到用戶牆上的用戶沒有對話框此方法。 params是共享包含的參數。

2

導入社會框架:

#import <Social/Social.h> 

-

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) { 

     SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 

     SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
      if (result == SLComposeViewControllerResultCancelled) { 

       NSLog(@"Cancelled"); 

      } else 

      { 
       NSLog(@"Done"); 
      } 

      [controller dismissViewControllerAnimated:YES completion:Nil]; 
     }; 
     controller.completionHandler =myBlock; 

     [controller setInitialText:@"Test Post from mobile.safilsunny.com"]; 
     [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]]; 
     [controller addImage:[UIImage imageNamed:@"fb.png"]]; 

     [self presentViewController:controller animated:YES completion:Nil]; 

    } 
    else{ 
     NSLog(@"UnAvailable"); 
    } 

} 

/

//Deprecated in iOS6 

    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]; 

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { 

     ACAccount *account = [[ACAccount alloc] initWithAccountType:accountType]; 
     NSLog(@"%@, %@", account.username, account.description); 
    }]; 
1

在這裏,我得到了答案,張貼image dataurl我們在一起需要增加社會。框架,這個框架在iOS6中可用。

只需在您的項目中添加Social.framework並添加自爆代碼。

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
{ 

    SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; 

    SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){ 
     if (result == SLComposeViewControllerResultCancelled) { 

      NSLog(@"ResultCancelled"); 

     } else 

     { 
      NSLog(@"Success"); 
     } 

     [controller dismissViewControllerAnimated:YES completion:Nil]; 
    }; 

    controller.completionHandler =myBlock; 

    [controller addURL:[NSURL URLWithString:@"https://itunes.apple.com/us/app/social-checkin/id504791401?mt=8"]]; 

    if (encoded_ImageData == nil) { 

     [controller addImage:[UIImage imageNamed:@"No_ImageFound.png"]]; 

    } 
    else 
    { 

    [controller addImage:[UIImage imageWithData:encoded_ImageData]]; 

    } 

    NSString *businessName; 

    //Set business name string to be passed on facebook 
    if (m_BusinessNameString == nil || [m_BusinessNameString isEqualToString:@""]) 
    { 
     businessName = @"Business name not specified!"; 
    } 
    else 
    { 
     businessName = [m_BusinessNameString uppercaseString]; 
    } 

    NSString *nameString = [NSString stringWithFormat:@"CHECKED IN @"]; 

    //user has checked in with his friends if sc-merchant 
    NSString *friendsString; 

    if ([checkedFriendsNameArray count] > 0) 
    { 
     NSMutableString *checkedFriendsTempStr = [[NSMutableString alloc] init]; 

     for (NSMutableString *checkedStr in checkedFriendsNameArray) 
     { 

      [checkedFriendsTempStr appendFormat:[NSString stringWithFormat:@"%@,",checkedStr]]; 

      friendsString = [NSString stringWithFormat:@"WITH %@",checkedFriendsTempStr]; 
     } 
    } 
    else 

    { 
     friendsString = [NSString stringWithFormat:@"WITH NO FRIENDS"]; 

    } 

    NSString *fname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userfname"]; 
    NSString *lname= [[NSUserDefaults standardUserDefaults] valueForKey:@"userlname"]; 

    NSString *name=[fname stringByAppendingString:[NSString stringWithFormat:@"%@",lname]]; 


    NSString *main_TextString =[NSString stringWithFormat:@"%@ \n %@ %@ %@ %@",upperCaseStatusString,name,nameString,businessName,friendsString]; 

    [controller setInitialText:main_TextString]; 

    [self presentViewController:controller animated:YES completion:Nil]; 

} 
else{ 

    NSLog(@"UnAvailable"); 
} 
1

在您的ViewController中添加以下代碼並導入下面的框架。

import FBSDKCoreKit 
import FBSDKLoginKit 
import FBSDKShareKit 

@IBAction func btnPostClick(_ sender: Any) 
{ 
     if (FBSDKAccessToken.current() != nil) 
     { 
      if FBSDKAccessToken.current().hasGranted("publish_actions"){ 
       postOnFB() 
      } 
      else 
      { 
       let loginManager = FBSDKLoginManager() 
       loginManager.logIn(withPublishPermissions: ["publish_actions"], from: self, handler: { (result, error) in 
        if error == nil{ 
         self.postOnFB() 
        } 
        else{ 
         print(error?.localizedDescription ?? "") 
        } 
       }) 
      } 
     } 
     else 
     { 
      let loginManager = FBSDKLoginManager() 
      loginManager.logIn(withPublishPermissions: ["publish_actions"], from: self, handler: { (result, error) in 
       if error == nil{ 
        self.postOnFB() 
       } 
      }) 
     } 
    } 

func postOnFB() 
    { 
     FBSDKGraphRequest(graphPath: "me/feed", parameters: ["message": "YOUR MESSAGE"], httpMethod: "POST").start { (connection, result, error) in 
      if error == nil{ 
       print("post id \(result ?? "")") 
      } 
      else{ 
       print("error is \(error?.localizedDescription ?? "")") 
      } 
     } 
    }