Skip to content

Instantly share code, notes, and snippets.

@dreadpiratepj
dreadpiratepj / creating a background task in iOS 4
Created June 16, 2010 05:07
creating a background task in iOS 4
- (void)applicationDidFinishLaunching:(UIApplication *)app {
if ([UIDevice currentDevice].multitaskingSupported) {
UIBackgroundTaskIdentifier *backgroundTask =
[app beginBackgroundTaskWithExpirationHandler:^{
/* just fail if this happens. */
NSLog(@"BackgroundTask Expiration Handler is called");
[app endBackgroundTask:backgroundTask];
}];
}
}
void *nmapFile(int sizeInBytes, FILE *myFile) {
if (myFile) {
/* Get the file descriptor from the FILE pointer. */
int fd = fileno(myFile);
if (fd >= 0) {
/* Map the file into an unused area of the process's address space. */
void *result = mmap(
NULL, /* No preferred address. */
sizeInBytes, /* Size of mapped space. */
PROT_READ, /* Read access. */
void *newScratchArea(int sizeInBytes) {
/*
Create a temporary file. This file will be automatically
destroyed by the system when our process exits.
*/
FILE *f = tmpfile();
if (f) {
/* Get the file descriptor from the FILE pointer. */
int fd = fileno(f);
if (fd >= 0) {