2015-06-04 12 views
5

Qual è il metodo di callback per FBSDKShareDialog quando ritorna all'app (dopo che l'utente ha terminato la creazione di un post)?FBSDKShareDialog callback per iOS

Questo è quello che ho per creare la finestra:

-(IBAction)post:(id)sender{ 
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init]; 
    content.contentURL = [NSURL URLWithString:self.spinShareURL]; 
    [email protected]"#spin"; 
    self.fromFacebook = true; 

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:nil]; 

} 

ho letto da qualche parte che c'è un callback

-(void)dialogDidComplete:(FBSDKShareDialog *)dialog{ 
} 

Ma questo non ha funzionato per me.

+0

Il delegato deve essere fatto su 'FBSDKSharingDelegate', credo, non su 'FBSDKShareDialog', dove si inserisce' nil': https://developers.facebook.com/docs/reference/ios/current/protocol/FBSDKSharingDelegate/ – Larme

risposta

14

ho trovato la soluzione alla seguente pagina:

http://jitu1990.blogspot.com/2015/05/share-with-facebook-from-ios-app.html

Ecco il mio codice finale:

-(IBAction)post:(id)sender{ 
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init]; 
    content.contentURL = [NSURL URLWithString:self.spinShareURL]; 
    content.contentTitle= [NSString stringWithFormat: @"%@'s spin", self.username]; 
    [email protected]"#spin"; 
    self.fromFacebook = true; 

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:self]; 

}- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results 
{ 
    NSLog(@"returned back to app from facebook post"); 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                message:@"Posted!" 
                delegate:self 
              cancelButtonTitle:nil 
              otherButtonTitles:nil]; 
    [alert show]; 
    double delayInSeconds = 1.0; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [alert dismissWithClickedButtonIndex:0 animated:YES]; 
    }); 
} 

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer 
{ 
    NSLog(@"canceled!"); 
} 

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error 
{ 
    NSLog(@"sharing error:%@", error); 
    NSString *message = @"There was a problem sharing. Please try again!"; 
    [[[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 
} 
+0

Sto usando queste funzioni delegate, dopo aver condiviso con successo il suo arrivo in sharerDidCancel, @ scientiffic puoi guidarmi – abdulrauf618

Problemi correlati