简体   繁体   English

iOS/Xcode:与之后打开已安装的应用程序相比,在连接到 Xcode 的情况下在 iPhone 上运行应用程序有区别吗?

[英]iOS/Xcode: is there a difference between running the App on an iPhone while connected to Xcode compared to opening the installed App afterwards?

I have a Timer which plays AVAudio at a specific time while the screen is locked (app in foreground when locked and plist setting 'Application does not run in background' set to YES).我有一个计时器,它在屏幕锁定时在特定时间播放 AVAudio(锁定时应用程序在前台,plist 设置“应用程序不在后台运行”设置为“是”)。

When I run my code while my iPhone is connected to Xcode it works as desired, playing audio while locked even when the iPhone has been locked for hours.当我在 iPhone 连接到 Xcode 的情况下运行我的代码时,它可以正常工作,即使 iPhone 已锁定数小时,也可以在锁定时播放音频。

Now if I disconnect my iPhone and just open the app by tapping the icon the audio won't be played if it's set for more than a minute.现在,如果我断开我的 iPhone 并通过点击图标打开应用程序,如果设置超过一分钟,音频将不会播放。

Is there a difference that causes this problem?是否存在导致此问题的差异? If I would publish my App to the AppStore which behaviour would my users get?如果我将我的应用程序发布到 AppStore,我的用户会得到哪些行为?

That 'Application does not run in background' flag is a very old flag that means your app does not support multitasking and should be terminated when the user presses the home button. “应用程序不在后台运行”标志是一个非常古老的标志,这意味着您的应用程序不支持多任务处理,应在用户按下主页按钮时终止。 There's no good reason I can think of to set that flag on a newly developed application.我想不出在新开发的应用程序上设置该标志的充分理由。 Unless you understand exactly what it's for and are positive that setting it to yes is the correct thing to do, don't do that.除非您确切了解它的用途并且确定将其设置为yes是正确的做法,否则不要这样做。

(That flag was added when iOS 4 was released, to allow apps that could not handle multi-tasking to request the old terminate-on-home-button behavior from iOS 3. Given that we're now 6 major iOS releases from iOS 4, it seems outdated.) (该标志是在 iOS 4 发布时添加的,以允许无法处理多任务的应用程序从 iOS 3 请求旧的 home 按钮终止行为。鉴于我们现在是 iOS 4 的 6 个主要 iOS 版本,好像过时了。)

So remove that flag.所以删除那个标志。 It probably doesn't have any impact on your question, but remove it or set it to no in any case.它可能对您的问题没有任何影响,但无论如何都请将其删除或将其设置为 no。

If you want to run a timer while the phone is locked and play sounds at designated times then you will probably need to set your app up as a background sound player, and ask for more background time when you get a message that you are going to the background.如果您想在手机锁定时运行计时器并在指定时间播放声音,那么您可能需要将您的应用设置为背景声音播放器,并在您收到要播放的消息时要求更多的背景时间背景。

That being said it's likely that Apple will reject your app.话虽如此,Apple 很可能会拒绝您的应用程序。 Running a timer from the background means that the processor on the phone has to run at full speed all the time, which will DRAMATICALLY reduce battery life.从后台运行计时器意味着手机上的处理器必须始终全速运行,这将大大缩短电池寿命。

Apple only allows a very small subset of apps to run in the background, and then only under specific circumstances (like a background sound playing app when the user is actively listening to music, or a navigation app that is actively tracking the user's location and notifying them when it's time to make a turn to follow directions.)苹果只允许一小部分应用程序在后台运行,然后只在特定情况下运行(比如用户积极听音乐时的背景声音播放应用程序,或者主动跟踪用户位置并通知的导航应用程序在该转弯时跟随指示。)

Should be no different.应该没有什么不同。 If you'd like to feel what do your users' feel then you can publish it to TestFlight which is the best app beta test environment.如果您想感受一下您的用户的感受,那么您可以将其发布到 TestFlight,这是最好的应用 Beta 测试环境。 Find some testers or try it yourself.找一些测试人员或自己尝试一下。 The directions should be to verify the playing logic and the sound file relationship which link to the connection.说明应该是验证链接到连接的播放逻辑和声音文件关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM