我正在開發一個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