oAuth/MGTwitterEngine 更改 iPhone 的用户?
我正在使用 oAuth/MGTwitterEngine 为 iphone 开发 twitter 应用程序 它所基于的来源在这里: http://icodeblog.com/wp -content/uploads/2010/09/iCodeOauth.zip
但我希望应用程序的用户能够返回并更改用户名和密码,例如,如果用户拥有多个 Twitter 帐户。
是否可以为按钮提供一个操作,以打开第一次打开应用程序时自动打开的页面。 (登录页面)
I'm working on a twitter app for the iphone using oAuth/MGTwitterEngine
The source it's based of is here: http://icodeblog.com/wp-content/uploads/2010/09/iCodeOauth.zip
But I want the user of the app to be able to go back and change the username and password if for an example the user has more than one twitter account.
Is it possible to give a button an action to open up the page that opens automatically the first time the app is opened. (The sign in page)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在深入研究代码并进行操作之后,我找到了一种方法来做到这一点,无论您在哪里获得框架,该方法都可能记录在案。
查看 iCodeOauthViewController.m,在
viewDidAppear:
内部,您可以在引擎上调用isAuthorized
,它会告诉您是否已通过身份验证。如果返回 yes,您可以调用引擎对象上的clearAccessToken
方法来清除该身份验证。当接下来调用controllerToEnterCredentialsWithTwitterEngine: delegate:
时,它将返回视图控制器以重新输入用户名和密码。编辑:
在 iCodeOauthViewController.m 内的 fo viewDidAppear: (line 46) 中,您将看到这一行:
如果用户尚未登录,此调用将返回您看到的登录屏幕。如果用户已登录,则返回 nil。如果控制器为零,则直接跳转到列表。
要“注销”用户,您可以使用此方法:
编辑2:
看来您的问题出在您的 tweet 方法内部。您已在推文尝试发送后添加了警报代码,如果用户未登录,这会导致崩溃。这是您的代码:
将其更改为如下所示:
}
请注意,我们现在检查是否我们在尝试发送推文之前经过身份验证,如果我们未获得授权,则会弹出警报。抱歉,我可能在发布警报的事情上误导了您,我误解了您的意思。
我建议尝试更多地了解 Objective-C 的工作原理并获取 熟悉调试器。如果您运行调试器并且您的应用程序崩溃,调试器将在崩溃的代码中停止,您可以查看堆栈中的函数调用以确定代码做错了什么。请参阅此堆栈溢出问题(具体是答案),了解有关如何更好地开始使用 Objective-C。我会推荐一些在线网站,例如 CocoaDevCentral 教程。 记住这一点。您已经有了一个良好的开端,尝试根据示例制作自己的东西。如果一个想法不能立即在你的主项目中实现,不要害怕做一个副项目来尝试它,即使它像找出另一种方法来完成 2 + 2 一样简单。希望这会有所帮助。
After digging into the code and playing with things I found a way to do this that is probably documented wherever you got the framework.
Looking at iCodeOauthViewController.m, inside of
viewDidAppear:
you can callisAuthorized
on the engine and it will tell you if you are authenticated or not. If this returns yes, you can then call theclearAccessToken
method on the engine object to clear that authentication. WhencontrollerToEnterCredentialsWithTwitterEngine: delegate:
is next called it will return the view controller for re-entering the user name and password.edit:
in iCodeOauthViewController.m inside fo viewDidAppear: (line 46) you will see this line:
this call returns the login screen that you see if the user is not yet logged in. If the user is logged in, it returns nil. If the controller is nil it jumps directly to the list.
to "log out" a user you could use this method:
edit 2:
Looks like your problem is inside of your tweet method. You have added the alert code after the tweet attempts to send, and that results in a crash if the user isn't logged in. Here is your code:
change it to look like this:
}
Notice that we now check to see if we are authenticated before trying to send the tweet, and if we are not authorized then pop up an alert instead. My apologies, I may have misled you with the releasing the alert thing, I misunderstood what you were saying.
I would recommend trying to understand a little more about how objective-c works and get familiar with the debugger. If you run the debugger and your app is crashing, the debugger will stop at the point in the code that is crashing, and you can look through the function calls in the stack to determine what the code is doing wrong. See this stack overflow question (specifically the answers) for more resources on how to get a better start with objective-c. I would recommend some of the online sites like CocoaDevCentral's tutorials. Remember this. You're off to a good start trying to make something your own based on an example. Don't be afraid to make a side project to play around with an idea if it's not immediately working out in your main project, even if it's something as simple as figuring out another way to do 2 + 2. Hope that helps.