how we run backgroundtask infinitely?

Joined
Oct 1, 2012
Messages
27
Reaction score
0
Points
1
hi,
is it possible to run background task infinitely in iPhone?




thanks.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
You will need to provide a bit more information before we can attempt to help. Which task do you want to run in the background? In iOS only about 7 or so APIs allow you to run in the background while the user is doing other things (Audio is one example).
 
OP
M
Joined
Oct 1, 2012
Messages
27
Reaction score
0
Points
1
Hi,

When iOS application enter into background, then also call particular method infinitely.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Moved to more appropriate forum.

Again, you'll need to be more specific. What exactly are you trying to do. As Raz0rEdge noted, only so much can be accomplished in the background.
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
When the user hits the Home button the newer versions of iOS, you will get a calls to applicationWillEnterBackground/applicationDidEnterBackground which indicate that you're going and have entered the background stage. You have a finite amount of time (about 5 seconds) to finish whatever you are doing (save state, kill connections, whatever) and then return to allow the OS to go on. If you don't do that, your application will be killed.

However, if you want to run something for a bit longer you can use beginBackgroundTaskWithExpirationHandler to continue a job in the background for a bit longer and it's probably possible to change these calls with the Expiration Handler to continue on infinitely. However, that is not really what this is designed for and you will end up depleting the battery of the iOS device pretty quickly..

Look these functions up on the developer reference for more information about them..
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top