Question: I have a requirement the user will register for watching videos. After the user has register then we need to hold the money for a period (varies depends on the video's ). Then after completing the period then we need to release the money to the end user. We are acting as a mediator for the user and the end user. How can i able to do that using paypal.

Is this functionality is available in paypal.
Any help is appreciated.
Thanks and regards.

Answer: 
Problem solved.

This is what happens. When an app is running in background and and it is executed a task, this task is running in background as well but the system allows only a certain amount of time (10s apron.) in order to safe battery. So it is only for a specific tasks (localization, download, etc.).

I my case I need a little more time so the solution is to define the task as a UIBackgroundTask in such a way that will be the task who notify the system when it is completed and thus can be terminated.

this is the code where it is called the task:

```

    UIApplication *application = [UIApplication sharedApplication];
    __block UIBackgroundTaskIdentifier background_task;
    background_task = [application beginBackgroundTaskWithExpirationHandler: ^{
        [application endBackgroundTask: background_task];
        background_task = UIBackgroundTaskInvalid;
    }];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self fiBGTemps:@(ALARM)];
        [application endBackgroundTask: background_task];
        background_task = UIBackgroundTaskInvalid;
    });

```

And here you can see the discussion on the Apple Forums where they explain this better than me.

[AppleForums discussion](https://devforums.apple.com/thread/185374?tstart=0)

I hope this helps.

Kanick
I suspect that chaining asynch blocks to play sounds at regular intervals is a bit of an overkill. Perhaps something simpler along the following lines would be easier to understand and maintain:

```
// To initiate the alarm:
[self fiBGTemps: ALARM];

- (void)fiBGTemps:(int)sender
{
    switch (sender) {
       ...
       case ALARM:
           dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                int count = 0;
                while (count < NUM_ALARM /* AND not interrupted by user? */) {
                    sleep(2);
                    AudioServicesPlaySystemSound(alarma);
                    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
                    count++;
                }
            });
            break;
        ...
    }
}

```