iOS应用程序打印时在后台运行

时间:2014-04-10 14:05:07

标签: ios printing

我有一个iOS应用程序,当订单进入并且效果很好时,它会自动将收据打印到热敏收据打印机。但是,如果应用程序在后台,则不会打印。是否可以在后台运行时进行打印?

2 个答案:

答案 0 :(得分:0)

只有少数情况下您可以在后台运行某些任务。请参阅Apple文档:https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20

例如:允许播放音频,获取用户位置,在后台从网络发送通知或某些数据。据我所知,在后台服务期间运行您自己的逻辑是不允许的(比如在应用程序进入睡眠/后台模式后一小时运行它)。

唯一可能是一个选项,就是利用你的应用程序在按下主页按钮后完成任务所需的时间。但有一个时间限制为10或15分钟。 我不知道这是否适合您的情况? 请参阅此stackoverflow问题:iOS application executing tasks in background 以及在后台运行任务的这段特殊代码:https://stackoverflow.com/a/11809211/2740112

答案 1 :(得分:0)

另一种选择是使用自iOS6以来引入的Guided Access。 有了它,您可以阻止退出该应用程序。仅在需要使用的设备上使用应用程序时,它才有用。 以下信息来自http://www.assistiveware.com/support/faq/page/136

要启用Guided Access,请执行以下操作:

Go to the Settings app on your device's home screen.
Tap General.
Tap Accessibility.
Under the Learning section (scroll down if necessary), tap Guided Access.
Toggle Guided Access to ON.
Tap Set Passcode and enter a four digit passcode. You will be prompted to enter it again.
(Optional) Toggle Enable Screen Sleep to ON if you want to be able to put your device to sleep with the Power button, otherwise the Power button will be disabled. 

要为应用启动Guided Access并阻止其退出,请执行以下操作:

Open the app that you want to lock in. 
Quickly press your device's Home button three times to bring up the Guided Access menu. 
Tap the Start button in the top right corner of the screen to activate Guided Access. A message stating "Guided Access Started" will briefly appear. 

要结束应用的Guided Access以便退出,请执行以下操作:

Quickly press your device's Home button three times to bring up the Guided Access menu.
Enter your four digit passcode when prompted. 
Tap the End button in the top left corner of the screen to end Guided Access. A message stating "Guided Access Ended" will briefly appear.

以下是Apple的知识库文章:http://support.apple.com/kb/ht5509