我正在开发一个iOs 5应用程序,并且我已经为iOs实施了Facebook SDK。我想和大家分享的图片让我的代码(不工作):我如何与Facebook SDK共享图片iOs
if (buttonIndex==3) {
if (facebook == nil)
{
// Setup Facebook connection
[self setUpFacebookConnection];
}else {
[self fbDidLogin];
}
}
}
- (void)setUpFacebookConnection
{
facebook = [[Facebook alloc] initWithAppId:@"245697495524266" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"])
{
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid])
{
NSArray* permissions = [[NSArray alloc] initWithObjects:
@"offline_access", @"publish_stream", @"publish_actions", @"photo_upload", nil];
[facebook authorize:permissions];
}
}
- (void)fbDidLogin{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
bannerview2.hidden=YES;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
// retrieve the current graphics context
CGContextRef context = UIGraphicsGetCurrentContext();
// render view into context
[self.view.layer renderInContext:context];
// create image from context
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// save image to photo album
UIImageWriteToSavedPhotosAlbum(image,
self,
nil,
@"image.png");
bannerview2.hidden=NO;
NSMutableString *message = [[NSMutableString alloc] init];
[NSString stringWithFormat:@"Resultado final %@: %d vs. %@: %d. Mi jugador hizo %d puntos y cometió %d faltas.",intnomlocal, puntsl, intnomvisitant, puntsv, puntsjugadorint, faltesjugadorint];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image, @"picture", message,@"message", nil];
[facebook requestWithGraphPath:@"me/feed"andParams:params andHttpMethod:@"POST" andDelegate:self];
}
所以它所有的作品,除非在共享图片中的一部分 - (无效)fbDidLogin。我该如何解决它?
fbDidLogin中究竟发生了什么以及“错误”行为在哪里? – LordT 2012-03-11 17:29:25
@LordT在fbDidLogin中,应用程序必须创建快照并将其上传到Facebook,但最后一部分不起作用。 – 2012-03-11 17:46:22