简体   繁体   中英

iOS app printing while running in the background

I have an iOS app that automatically prints a receipt to a thermal receipt printer when an order comes in and works great. However, if the app is in the background, it does not print. Is it possible to allow it to print while running in the background?

There are only a few occasions you are allowed to run certain tasks in the background. See the Apple documentation: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20

For example: playing audio, fetching the user location, sending notification or certain data from network in the background is allowed. Running your own logic during a background service is, as far as I understood, not allowed (like running it one hour after your app is gone to sleep/background mode).

The only thing that is perhaps an option, is to utilize the time your app has to finish an task after the home button is pressed. There is a timelimit however of 10 or 15 minutes. I don't know if this is suitable for your situation? See this stackoverflow question: iOS application executing tasks in background And this particular piece of code to run the task in the background: https://stackoverflow.com/a/11809211/2740112

Another option is to use Guided Access, which is introduced since iOS6. With it, you can prevent exiting the app. It's only usefull when using only the app on the device that needs to be used. Information below from http://www.assistiveware.com/support/faq/page/136 :

To turn on Guided Access, do the following:

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. 

To start Guided Access for an app and prevent it from being exited, do the following:

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. 

To end Guided Access for an app so it can be exited, do the following:

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.

Here's the knowledgebase article of Apple: http://support.apple.com/kb/ht5509

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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