Rich
Rich

Reputation: 77

iOS - background app

I have an iOS app, that is an TCP server, that receives a command an talks to something on the devices hardware.

Example commands are:

1: make a connection using blue tooth

2: get devices mac address

3: read from an audio card reader

I need this app to always be running. Can someone advise the best course of action

Upvotes: 0

Views: 660

Answers (2)

borrrden
borrrden

Reputation: 33421

Everybody "needs their app to always be running" but very rarely is that actually true. Apple does not want you needlessly draining the user's battery so they have set up some rules about background tasks. You are only allowed to perform a long running background task in certain cases. Yours does not seem to fit any.

However, there are two bluetooth background modes (One is iOS 5.0+ and the other is iOS 6.0+). If your app is going to be consistently talking to an external bluetooth accessory then your app will probably get past review. If it is just sitting there idle waiting for commands then it will most likely be rejected. By far the reason I most often see people whining about on Stack Overflow is "my app got rejected because Apple said I don't use my declared background mode correctly." If the reason for the background mode is not very obvious then I bet it will be rejected. Apple will put your app into the background, see that it seems to do nothing, and reject it.

Upvotes: 2

Priyank Gandhi
Priyank Gandhi

Reputation: 1253

For background task you can use following code:

[self startBackgroundProcess];

Use above code in your didFinishLaunchingWithOptions:

IN that method write below code:

-(void)startBackgroundProcess
{
    UIBackgroundTaskIdentifier bgTask = 0;
    UIApplication *app=[UIApplication sharedApplication];
    bgTask=[app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
    }];

    -----
}

In the place of ---- you can write your code

Upvotes: 0

Related Questions