facebook fbDidLogin appdelegate外面(facebook fbDidLogin outside appdelegate)
我已经阅读了很多关于facebook登录的问题,但直到没有成功解决我的问题。 到目前为止我已经制作了一些应用程序,但我之前从未搞过appDelegate。
问题是我想调用除了委托之外的类内部的fbDidLogin方法。
到目前为止,fbDidLogin正在appDelegate中调用,但我希望能够在登录发生后更改视图并询问用户信息。
我的代码到目前为止:AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; facebook = [[Facebook alloc] initWithAppId:SHKCONFIG(facebookAppId) andDelegate:self]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } return YES; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [facebook handleOpenURL:url]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [facebook handleOpenURL:url]; } // This one is called correctly - (void)fbDidLogin { NSLog(@"[DELEGATE] Deu login!"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; }
我自己上课的facebook登录按钮:
- (void)loginFacebook { if (![facebook isSessionValid]) { NSLog(@"[LOGIN] Facebook session invalid"); NSArray * permissions = [[NSArray alloc] initWithObjects: @"email", @"user_birthday", nil]; [facebook authorize:permissions]; [permissions release]; } else { NSLog(@"[LOGIN] Facebook session valid"); [facebook requestWithGraphPath:@"me" andDelegate:self]; } } // I want this one to work so I can ask for user info at the end of it - (void)fbDidLogin { NSLog(@"[LOGIN][FB] Deu login!"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; [facebook requestWithGraphPath:@"me" andDelegate:self]; }
对不起,如果不清楚,如果您需要更多信息,请告诉我。
I have read many questions about the facebook login but until not I didnt succeed on solving my problem. I have made a few apps so far but I have never messed with the appDelegate before.
The thing is that I want to call the fbDidLogin method that is inside my class other than delegate.
Until now, fbDidLogin is being called in the appDelegate, but I want to be able to change the view and ask for user info after the login happens.
My code so far: AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; facebook = [[Facebook alloc] initWithAppId:SHKCONFIG(facebookAppId) andDelegate:self]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } return YES; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [facebook handleOpenURL:url]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [facebook handleOpenURL:url]; } // This one is called correctly - (void)fbDidLogin { NSLog(@"[DELEGATE] Deu login!"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; }
My own class with the facebook login button:
- (void)loginFacebook { if (![facebook isSessionValid]) { NSLog(@"[LOGIN] Facebook session invalid"); NSArray * permissions = [[NSArray alloc] initWithObjects: @"email", @"user_birthday", nil]; [facebook authorize:permissions]; [permissions release]; } else { NSLog(@"[LOGIN] Facebook session valid"); [facebook requestWithGraphPath:@"me" andDelegate:self]; } } // I want this one to work so I can ask for user info at the end of it - (void)fbDidLogin { NSLog(@"[LOGIN][FB] Deu login!"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; [facebook requestWithGraphPath:@"me" andDelegate:self]; }
I sorry if this is not clear, if you need more info let me know.
原文:https://stackoverflow.com/questions/9930344
最满意答案
有关本机接口,请参阅任务栏扩展(Windows) 。 具体来说,我认为您正在寻找ICustomDestinationList :: AddUserTasks方法。
如果您正在使用.Net 4+,您现在可以在System.Windows.Shell命名空间中使用内置类执行大量此类操作,而不是按照Coding Gorilla的建议添加Windows API代码包。 请参阅示例System.Windows.Shell命名空间
For the native interfaces, see Taskbar Extensions (Windows). Specifically, I think you're looking for the ICustomDestinationList::AddUserTasks method.
If you're using .Net 4+, you can now do a lot of this stuff with built-in classes in the System.Windows.Shell namespace, rather than adding the Windows API Code Pack as suggested by Coding Gorilla. See for example System.Windows.Shell namespace
相关问答
更多-
有关本机接口,请参阅任务栏扩展(Windows) 。 具体来说,我认为您正在寻找ICustomDestinationList :: AddUserTasks方法。 如果您正在使用.Net 4+,您现在可以在System.Windows.Shell命名空间中使用内置类执行大量此类操作,而不是按照Coding Gorilla的建议添加Windows API代码包。 请参阅示例System.Windows.Shell命名空间 For the native interfaces, see Taskbar Exten ...
-
显然,每次唤醒设备时, startLockTask()都会被执行。 如果它已经处于固定模式,这将再次运行,并导致问题。 最后,我测试了我的初始假设,编辑了onResume()函数, 只有在没有固定时才执行startLockTask() 。 这似乎解决了问题(即使我不明白为什么会出现这种行为 )。 如果有人能解释这一点,会很高兴。 我正在为任何碰到这个问题的人发布答案。 的onResume() @Override protected void onResume() { supe ...
-
不,这是不可能的。 您提供的文档链接仅用于扩展。 没有选项可以在manifest.json中为应用程序固定托管应用程序的选项卡。 No, it's impossible. The docs link you gave is for only extensions. There is no option to make pinned the hosted app's tab in manifest.json for apps.
-
也许只需使用long lastTimePressed=0L; System.currentTimeMillis(); if(System.currentTimeMillis()-lastTimePressed>2000) finish(); 2000年为Toast.Length_SHORT ,3500为Toast.LENGTH_LONG long lastTimePressed=0L; @Override public void onBackPressed (){ if(System.curren ...
-
在你的endpoint.ex文件中,有一行指定了静态插件应该处理的内容。 我看起来像下面这样 plug Plug.Static, at: "/", from: :my_app, gzip: false, only: ~w(css fonts images js favicon.ico robots.txt) 您需要将您的文件放在图像目录中,或者添加一个类似于favicon.ico条目的website_icon.svg 。 In your endpoint.ex file, there is a l ...
-
我将定义一个自定义任务,该任务将(当被调用时)为processhtml任务设置选项并运行它。 有点像: grunt.task.registerTask('foo', 'My foo task.', function() { grunt.config("processhtml.dev", { options: { data: { appJsgrunt: file.expand('dist/**/*.js') } } }); grunt.ta ...
-
.Net内存分析器和
固定(.Net memory profiler and [2021-11-25]pinned) 原因是List静态构造函数分配了一个空的T数组。使用Reflector查看其代码: static List() { List._emptyArray = new T[0]; } The reason is that List static constructor allocate an empty array of T. Take a look on its code using Reflector: static List() { List ._emptyArray = new ... -
每次更新后决定重新启动。 Decided to reboot after each update.
-
保持NSScrollView固定(Keep NSScrollView pinned down)[2021-02-17]
我认为您应该能够使用NSManagedObjectContext通知,NSManagedObjectContextObjectsDidChangeNotification。 创建自定义NSTableView类并为该通知添加观察者: @implementation CustomTable -(void)awakeFromNib { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollTable: ... -
NSIS没有此接口的本机支持,因此您必须使用插件。 如果你想避免使用第三方插件(由我编写),那么你可以改用System插件: !include "LogicLib.nsh" !include "Win\COM.nsh" ; NSIS v3+ !macro UnpinShortcut lnkpath Push $0 Push $1 !insertmacro ComHlpr_CreateInProcInstance ${CLSID_StartMenuPin} ${IID_IStartMenuPinnedLis ...