iPhone Webview onBackground 事件?

发布于 2024-10-15 16:18:59 字数 192 浏览 1 评论 0原文

我正在使用phonegap 开发一个iphone 应用程序。现在我想在应用程序进入后台时保持会话状态。即使应用程序被操作系统杀死,我也想保持这种状态。 (只需考虑在应用程序进入后台时在 javascript 中保存一些变量)

有什么方法可以做到这一点吗?当应用程序移至后台时,UIWebView 是否允许执行 JavaScript?

谢谢

I am developing a iphone app using phonegap. Now I want to maintain a session state when the app goes into the background. I want to persist that state even if the app gets killed by the OS. (Just consider saving some variables in javascript when the app goes into background)

Is there some way I can do that? Does the UIWebView allows javascript to execute when the app is moving to background?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光礼记 2024-10-22 16:18:59

我认为不存在这样的事件,所以我建议您在应用程序中更改状态时始终保存状态。因此,您不必在关闭应用程序时保存。

I don´t think that there is such an event, so I would suggest that you always save your state if you change it within your app. So you dont have to save while closing the app.

雨夜星沙 2024-10-22 16:18:59

我不知道phoneGap,但在objective-c中你可以添加一个观察者(注册应用程序进入后台时的通知)

 [[NSNotificationCenter defaultCenter] addObserver:self
    selector: @selector(enteredBackground) 
    name: UIApplicationDidEnterBackgroundNotification
    object: nil];

然后创建一个名为enterBackground的方法,你可以放置如下代码:

[myWebView stringByEvaluatingJavaScriptFromString:@"Do something in javascript"];

在哪里替换< code>使用您想要执行的代码在 javascript 中执行某些操作。
请参阅: http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instm/UIWebView/stringByEvaluatingJavaScriptFromString

I don't know about phoneGap, but in objective-c you can add an observer (register for notifications for when the app goes into the background)

 [[NSNotificationCenter defaultCenter] addObserver:self
    selector: @selector(enteredBackground) 
    name: UIApplicationDidEnterBackgroundNotification
    object: nil];

Then create a method named enteredBackground, and you can put code like:

[myWebView stringByEvaluatingJavaScriptFromString:@"Do something in javascript"];

where you replace the Do something in javascript with the code you want to execute.
See this: http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instm/UIWebView/stringByEvaluatingJavaScriptFromString:

╭ゆ眷念 2024-10-22 16:18:59

我认为没有办法实现这一点。如果有人找到解决方案,请分享。

我想做的就是在我的 webview 中获取“app-going-to-the-background”事件,以便我可以在此时运行一些 javascript 代码。它类似于在 applicationWillResignActivity 中运行 Objective-C 代码。因此,如果有人有如何做到这一点的工作示例,请回复。

否则,我将不得不将此视为“无法完成的工作”:(

I think there no way to achieve this. If anyone has found a solution, please share.

All I am trying to do is get the "app-going-to-the-background" event in my webview so that I can run some javascript code at that point. It is similar to running objective-c code in applicationWillResignActivity. So if anyone has working example of how this can be done, please reply.

Otherwise, I will have to consider this as "cant-be-done-job" :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文