#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    76
    Rep Power
    20

    Run task in background


    So I am creating an application that will run a python script in the background. I have the code to do this (below), but I don't know exactly how to implement it.

    Ideally, the user would launch the app, click the "Start" button and it would then sent the app into the background and start the python script execution. The user would then open their browser (on a separate computer) and navigate to the ip address of the device and the listening port to access the UI.

    This code makes your iOS app run indefinitely in the background. Copy and paste the below methods into a singleton / manager which handles the tasks you need to perform in the background.

    The code below is within my MyApp.h and MyApp.m files. I just don't know how to execute the background task on the button click.

    Code:
    // @interface
    
    // Declare Private property
    @property (nonatomic) UIBackgroundTaskIdentifier backgroundTask;
    
    //@end
    // ...
    
    // Copy into
    //@implementation 
    
    - (void)setupBackgrounding {
        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(appBackgrounding:)
                                                     name: UIApplicationDidEnterBackgroundNotification
                                                   object: nil];
        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(appForegrounding:)
                                                     name: UIApplicationWillEnterForegroundNotification
                                                   object: nil];
    }
    
    - (void)appBackgrounding: (NSNotification *)notification {
        [self keepAlive];
    }
    
    - (void) keepAlive {
        self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
            [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
            self.backgroundTask = UIBackgroundTaskInvalid;
            [self keepAlive];
        }];
    }
    
    - (void)appForegrounding: (NSNotification *)notification {
        if (self.backgroundTask != UIBackgroundTaskInvalid) {
            [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
            self.backgroundTask = UIBackgroundTaskInvalid;
        }
    }
    Being educated does not make you intelligent
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    76
    Rep Power
    20
    I actually got this figured out. If anyone in interested in the tool I created (which was the purpose of this question), you can read about it here:

    Introducing the iOS Reverse Engineering Toolkit | Application Security News, Research, Trends – Veracode Blog
    Being educated does not make you intelligent

IMN logo majestic logo threadwatch logo seochat tools logo