[英]Integrating iOS6 facebook function
我正在嘗試使用iOS6 Facebook功能將應用程序的屏幕截圖導出到Facebook。 按下按鈕后,如何在應用程序內部顯示選項?
下面是我當前的代碼。 我想截取屏幕截圖,同時使用iOS6 Facebook功能將其導出到Facebook。
- (IBAction)export1:(id)sender{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
exporting.hidden=YES;
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// Iterate over every window from back to front
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen])
{
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [window center].x, [window center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [window transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[window bounds].size.width * [[window layer] anchorPoint].x,
-[window bounds].size.height * [[window layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[window layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
}
}
// Retrieve the screenshot image
CGRect contentRectToCrop = CGRectMake(0, 70, 740, 740);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], contentRectToCrop);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil);
這是使用iOS6中內置的Facebook SDK輕松將圖像發布到Facebook的方法。 很高興這對您有任何幫助。 快樂的編碼:)
蘋果開發者網站為整合Twitter和Facebook之類的社交體驗提供了新的Social.framework。
請參考這里 。
@Clarence我認為您應該查看適用於iOS的最新Facebook SDK
它還提供了一些有關如何在iOS 6中在Facebook上發布圖像的教程。
只需下載SDK,您就會在Documents文件夾中找到示例代碼,其中包括示例HelloFacebookSample,該示例顯示了如何在iOS 6中的Facebook上發布圖像。
您只需要通過此方法傳遞圖像對象-
[FBNativeDialogs presentShareDialogModallyFrom:self initialText:nil image:croppedImage url:nil handler:nil];
使用上面的方法之前,你需要正確地遵循v 3.1的安裝說明在這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.