1

嗨,我正在尝试启用 IBAction 以在用户的​​时间线上发布,而他们有一个活动部分。我收到一条错误消息,说明;函数“x”的隐式声明在 C99 中无效。我一直在阅读有关该问题的帖子,但没有运气,老实说,我不确定我是否做对了。我更新了我的 fb 应用程序的权限,并从 Graph API Explorer 获取了目标代码,但我不知道我是否在我的代码上正确实现了它。

这是我的发布方法:

-(void) aPost
{
    NSMutableDictionary<FBGraphObject> *object =
    [FBGraphObject openGraphObjectForPostWithType:@"website"
                                            title:@"CR Taxi APP"
                                            image:@"http://a4.mzstatic.com/us/r1000/047/Purple4/v4/05/cc/f2/05ccf23f-a409-1e73-a649-a5e6afc4e6eb/mzl.llffzfbp.175x175-75.jpg"
                                              url:@"https://itunes.apple.com/cr/app/cr-taxi/id674226640?mt=8"
                                      description:@"La nueva aplicación para llamar taxis!"];;

    [FBRequestConnection startForPostWithGraphPath:@"{id_from_create_call}"
                                       graphObject:object
                                 completionHandler:^(FBRequestConnection *connection,
                                                     id result,
                                                     NSError *error) {
                                     // handle the result
                                 }];

}

这是我的行动方法

- (IBAction)publishAction:(id)sender {

    if ([FBSession.activeSession.permissions
         indexOfObject:@"publish_actions"] == NSNotFound) {

        NSArray *writepermissions = [[NSArray alloc] initWithObjects:
                                     @"publish_stream",
                                     @"publish_actions",
                                     nil];


        [[FBSession activeSession]requestNewPublishPermissions:writepermissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *aSession, NSError *error){
            if (error) {
                NSLog(@"Error on public permissions: %@", error);
            }
            else {
             **not on the code //( error on this one)   aPost(aSession, error);
            }


        }];

    }
    else {
        // If permissions present, publish the story
     **not on the code //(not an error on this one)  aPost(FBSession.activeSession, nil);
    }


}

请帮忙!

谢谢!

4

3 回答 3

0
- (IBAction)shareViaFacebook:(id)sender {


if (FBSession.activeSession.isOpen) {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   [NSString stringWithFormat:@"%@.  Join on Linute.",self.userNameLabel.text], @"name",
                                   //@"Build great social apps and get more installs.", @"caption",
                                   locationString, @"description",
                                   //@"http://www.linute.com/", @"link",
                                   eventPicString, @"picture",//imageURL
                                   nil];

    // Make the request
    [FBRequestConnection startWithGraphPath:@"/me/feed"
                                 parameters:params
                                 HTTPMethod:@"POST"
                          completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              if (!error) {
                                  // Link posted successfully to Facebook
                                  NSLog(@"result: %@", result);
                              } else {
                                  // An error occurred, we need to handle the error
                                  // See: https://developers.facebook.com/docs/ios/errors
                                  NSLog(@"%@", error.description);
                              }
                          }];
}else{

    FBSession *session = [[FBSession alloc] initWithPermissions:@[@"public_profile", @"email",@"user_friends",@"publish_actions"]];
    [FBSession setActiveSession:session];

    [session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

        if (FBSession.activeSession.isOpen) {

            [self shareViaFacebook:nil];

        }else{
            [self shareViaFacebook:nil];


        }
    }];
}
于 2015-04-02T14:01:17.277 回答
0

我猜编译器错误实际上是“函数'aPost'的隐式声明是无效的C99”,尽管您的操作方法代码的格式在编写时是不稳定的。编译器只会在第一次遇到对 aPost 的函数调用时产生该错误消息。

aPost 被编写为一个没有返回值且不接受参数的方法。您试图将其作为 C 函数调用,并向其传递两个参数,编译器将其解释为一个全新的函数。由于 aPost 是用所有硬编码字符串编写的,您可能只想更改对 aPost(arg1, arg2); 的调用。给[自己发帖];(前提是 aPost 和 publishAction 在同一个类中)。

于 2013-08-28T03:22:28.833 回答
0

试试这个:可能会帮助你

//在你的 ViewController.h 文件中写入这一行

    @property (strong, nonatomic) NSMutableDictionary *postParams;

//在查看Controller.m文件

- (void)viewDidLoad
  {
     self.postParams =
     [[NSMutableDictionary alloc] initWithObjectsAndKeys:
 [UIImage imageNamed:@"Default.png"], @"picture",
 @"Facebook SDK for iOS", @"name",
 @"build apps.", @"caption",
 @"testing for my app.", @"description",
 nil];

[self.postParams setObject:@"hgshsghhgsls" forKey:@"message"];

 }
 - (IBAction)SharePressed:(id)sender {

 @try {


    [self openSession];
    NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists",@"read_stream", nil];

       [[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
                                               completionHandler:^(FBSession *session, NSError *error) {
                                                   /* handle success + failure in block */
                                                   if (![session isOpen]) {
                                                       [self openSession];
                                                   }
                                               }];

    [FBRequestConnection   startWithGraphPath:@"me/feed" parameters:self.postParams HTTPMethod:@"POST"
                            completionHandler:^(FBRequestConnection *connection,id result,NSError *error) {
                                NSString *alertText;
                                if (error) {                                               
                                  alertText = [NSString stringWithFormat:@"error: domain = %@, code = %d, des = %@",error.domain, error.code,error.description];  
                                }
                                else
                                {
                                    alertText=@"Uploaded Successfully";
                                    [self ResetAllcontent];
                                }
                                // Show the result in an alert
                                [[[UIAlertView alloc] initWithTitle:@"Result" message:alertText delegate:self cancelButtonTitle:@"OK!"
                                                  otherButtonTitles:nil]show];
                            }]; 





}
@catch (NSException *exception) {
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please Login" message:@"For Sharing on facbook please login with facbook" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
    [alert show];
}
@finally {
}
}

- (void)openSession
 {
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

[FBSession openActiveSessionWithReadPermissions:nil
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,
   FBSessionState state, NSError *error) {
     [appDelegate sessionStateChanged:session state:state error:error];
 }];

ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) &&
    (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){

    NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
    id account;
    if (fbAccounts && [fbAccounts count] > 0 &&
        (account = [fbAccounts objectAtIndex:0])){

        [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
            //we don't actually need to inspect renewResult or error.
            if (error){

            }
        }];
    }
}
}
}

//=====在您的 plist 文件中执行 URLTypes=>Item 0=> URL Schemes =>Item 0=>fbyourfacebookId

FacebookAppID-你的facebookID

在此处输入图像描述 是的,不要忘记在 developer.facebook.com 上创建 facebook id,并根据需要授予权限

于 2013-08-28T04:08:05.280 回答