ipa运行时如何禁用屏幕关闭

Posted

技术标签:

【中文标题】ipa运行时如何禁用屏幕关闭【英文标题】:how is disable screen off when ipa is running 【发布时间】:2018-05-11 13:47:59 【问题描述】:

我的 ios IPA 有问题。我希望在我的应用程序运行时屏幕不会关闭。为此,当我用谷歌搜索时,我得到的答案是使用UIApplication.sharedApplication().idleTimerDisabled = true。所以我在 AppDelegate.cs 中尝试了这个。但这在我的 ios IPA 中不起作用。因为一段时间后屏幕将关闭。我在*** with high repution 上也得到了同样的答案

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    
        global::Xamarin.Forms.Forms.Init();
        global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
        UIApplication.SharedApplication.IdleTimerDisabled = true; 
        formsApp = new App();
        LoadApplication(formsApp);             
        return base.FinishedLaunching(app, options);
    

你能告诉我在我的代码中做错了什么吗?感谢您的解决方案和代码。

【问题讨论】:

【参考方案1】:

这是正确的方法,尽管在您的情况下,鉴于应用程序是传递的参数之一,您可以调用

app.IdleTimerDisabled = true;

我看到你在打电话

base.FinishedLaunching(app, options);

在你的函数结束时 - 我不使用 xamarin,但我突然想到这个调用可能将它设置回 false,所以你可以尝试先调用它,然后在之后将其设置为 true:

base.FinishedLaunching(app, options);
app.IdleTimerDisabled = true;
return true;

【讨论】:

以上是关于ipa运行时如何禁用屏幕关闭的主要内容,如果未能解决你的问题,请参考以下文章