NSTimer or NSThread in iOs 4 background mode

2019-07-07 01:48发布

I have to keep a NSThread or NSTimer when my iPhone application goes into background mode. Is it possible ? I have enabled the background modes in info.plist and opened readstream and writestream as follows ...(I am using UDP)

CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType,kCFStreamNetworkServiceTypeVoIP);

CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

But when my application goes to background and locked state, NSThread or NSTimer is not calling . So please suggest me how to achieve background threading in iPhone background locked state ?

3条回答
Viruses.
2楼-- · 2019-07-07 02:29

I wonder this too.

I want to update my CLLocation (current location) object every five minutes. The only way that i know of is to do this with NSTimer.

What is your advice if this isn't possible?

查看更多
神经病院院长
3楼-- · 2019-07-07 02:40

For some applications(audio, location, voip) Apple allows background execution on supported devices.

Support for some types of background execution must be declared in advance by the application that uses them. An application declares this support by including the UIBackgroundModes key in its Info.plist file. Its value is an array that contains one or more strings with the following values:

audio
location
voip
查看更多
smile是对你的礼貌
4楼-- · 2019-07-07 02:41

Instead of NSTimer use UILocalNotification which can fire notifications both when the app is in the background and in the foreground.

查看更多
登录 后发表回答