【发布时间】:2011-09-27 08:22:59
【问题描述】:
我刚刚浏览了 Facebook 开发人员的“入门 > 移动应用”文档。他们提供了代码来请求访问信息的权限,但他们没有指定该代码应该去哪里。
你能告诉我把代码放在哪里吗?因为我不想放错地方。
我要添加的代码:
NSArray* permissions = [[NSArray arrayWithObjects:
@"publish_stream", @"offline_access", nil] retain];
[facebook authorize:permissions delegate:self];
我的 appDelegate 代码:
#import "iOSTestAppDelegate.h"
@implementation iOSTestAppDelegate
@synthesize facebook;
@synthesize viewController=_ViewController;
@synthesize window=_window;
@synthesize managedObjectContext=__managedObjectContext;
@synthesize managedObjectModel=__managedObjectModel;
@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
/* Step 2. Within the body of the application:didFinishLaunchingWithOptions: method create instance of the Facebook class using your app id */
facebook = [[Facebook alloc] initWithAppId:@"********"];
/* Step 3. Once the instance is created, check for previously saved access token information. */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
/* Step 4. Check for a valid session and if it is not valid call the authorize method which will both signin the user and prompt the user to authorize the app: */
if (![facebook isSessionValid]) {
[facebook authorize:nil delegate:self];
}
return YES;
}
/* Step 5. Add the application:handleOpenURL: method to the AppDelegate with a call to the facebook instance: */
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
/* Step 6. Implement the fbDidLogin method from the FBSessionDelegate implementation. In this method you will save the user's credentials specifically the access token and corresponding expiration date. */
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
...
@end
【问题讨论】:
标签: iphone ios facebook permissions