Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:54:15+00:00 2026-06-11T19:54:15+00:00

I am creating a application that will continue running on back ground. When the

  • 0

I am creating a application that will continue running on back ground.
When the device is connected to the MAC and debugging, but when I disconnect and run the application standalone, it will finish in 10min. Is there any setting or my codings are wrong?

My code is appdeledate.h is

#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>


@class TashouNoEnViewController;

@interface TashouNoEnAppDelegate : NSObject <UIApplicationDelegate,GKSessionDelegate,GKPeerPickerControllerDelegate> {
    UIWindow *window;
    TashouNoEnViewController *viewController;
    GKSession *mySession;
    IBOutlet UITextField *messageTextField;
    UIBackgroundTaskIdentifier backgroundTaskIdentifer;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet TashouNoEnViewController *viewController;

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end

appdelegate.M is

#import "TashouNoEnAppDelegate.h"
#import "TashouNoEnViewController.h"
#define kSessionID @"_tashounoen"

@implementation TashouNoEnAppDelegate

@synthesize window;
//=_window;
@synthesize viewController;
@synthesize navigationController=_navigationController;

NSString *message102;

NSString* a_home_dir;
NSString* a_doc_dir;
NSString* a_path;
NSString *switchcheck;
NSInteger myselfint;
NSInteger swithchcheckint;
NSInteger runcount;
NSInteger runcount2;
NSInteger totalruncount;
UIBackgroundTaskIdentifier bgTask;
NSTimer *caallTimer;
NSTimer *caallTimer2;
 NSString *message100;
 NSString *message200;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


- (void)applicationWillResignActive:(UIApplication *)application
{
 /**
    NSLog(@"applicationWillResignActive");
    // NSLog(@"%s", __PRETTY_FUNCTION__);
    UIApplication* app = [UIApplication sharedApplication];
    NSAssert(backgroundTaskIdentifer == UIBackgroundTaskInvalid, nil);
    backgroundTaskIdentifer = [app beginBackgroundTaskWithExpirationHandler:^{

        //  NSLog(@"expired!");
        dispatch_async(dispatch_get_main_queue(), ^{
            if (backgroundTaskIdentifer != UIBackgroundTaskInvalid) {
                [app endBackgroundTask:backgroundTaskIdentifer];
                backgroundTaskIdentifer = UIBackgroundTaskInvalid;
            }
        });
    }];
    **/
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    self.window.rootViewController = self.navigationController;
    runcount=0;
    totalruncount=0;
    NSLog(@"applicationDidEnterBackground");
   caallTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(CAALL2) userInfo:nil repeats:NO];

    void (^handler)(void)  = ^{
            bgTask = UIBackgroundTaskInvalid;
    };
   bgTask = [application beginBackgroundTaskWithExpirationHandler:handler];
    [application setKeepAliveTimeout:600 handler:^{


         bgTask = [application beginBackgroundTaskWithExpirationHandler:handler];
        [caallTimer invalidate];
        caallTimer = nil;

        caallTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(CAALL2) userInfo:nil repeats:NO];


    }];

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{


    NSLog(@"applicationWillEnterForeground");
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{


    NSLog(@"applicationDidBecomeActive");
}

- (void)applicationWillTerminate:(UIApplication *)application
{


    NSLog(@"applicationWillTerminate");
}

- (void)session:(GKSession *)session connectionWithPeerFailed:(NSString *)peerID withError:(NSError *)error {
}

- (void)session:(GKSession *)session didFailWithError:(NSError *)error {

}

- (void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID {

    NSError *error;
    if(![mySession acceptConnectionFromPeer:peerID error:&error]) {
    } else {

    }
}


-(void)CAALL2

{


            [mySession disconnectFromAllPeers];
            [mySession release];
            mySession = nil;
            mySession = [[GKSession alloc] initWithSessionID:kSessionID displayName:nil sessionMode:GKSessionModePeer];
            mySession.delegate = self;
            [mySession setDataReceiveHandler:self withContext:nil];
            mySession.available = YES;

caallTimer = [NSTimer scheduledTimerWithTimeInterval:500 target:self selector:@selector(CAALL2) userInfo:nil repeats:NO];
  //  if (totalruncount<21){

  //  }

}
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
    switch (state) {
        case GKPeerStateAvailable:
            NSLog(@"GKPeerStateAvailable");
            [mySession connectToPeer:peerID withTimeout:31.0f];
            break;
        case GKPeerStateUnavailable:
            break;
        case GKPeerStateConnected:
            [self btnSend:peerID];
   break;
        case GKPeerStateDisconnected:
            break;
        case GKPeerStateConnecting:
            break;
        default:
            break;
    }
}

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context {


    message100 = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
 //   NSLog(@"frompeerid%@",peer);
 //   NSLog(@"get%@",message100);
    int checkdata = [message100 intValue ];
    if (checkdata==111)
    {
        message100 =@"111";
        UIApplication *app  = [UIApplication sharedApplication];
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        NSDate *notificationDate = [NSDate dateWithTimeIntervalSinceNow:0];
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.fireDate  = notificationDate;
        notification.timeZone  = [NSTimeZone systemTimeZone];
        notification.alertBody = message100;
        [app scheduleLocalNotification:notification];
        [notification release];
    }
    else if (checkdata==110)
    {
        message100 =@"110";
        UIApplication *app  = [UIApplication sharedApplication];
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        NSDate *notificationDate = [NSDate dateWithTimeIntervalSinceNow:0];
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.fireDate  = notificationDate;
        notification.timeZone  = [NSTimeZone systemTimeZone];
        notification.alertBody = message100;
        [app scheduleLocalNotification:notification];
        [notification release];
    }

}

- (void) mySendDataToPeers:(NSData *) data:(NSString *)peerID
{
    NSError* error = nil;
    NSLog(@"senddata");
    if (mySession)
       NSLog(@"mypeerid%@",peerID);

                [mySession sendData:data toPeers:[NSArray arrayWithObject:peerID] withDataMode:GKSendDataReliable error:&error];
    if (error) {
        NSLog(@"%@", error);
    }
}


-(void) btnSend:(NSString *)peerID{

    a_home_dir = NSHomeDirectory();
    NSString* a_doc_dir = [a_home_dir stringByAppendingPathComponent:@"Documents"];
    a_path = [a_doc_dir stringByAppendingPathComponent:@"userdata.plist"];

    NSDictionary *plist2 = [NSDictionary dictionaryWithContentsOfFile:a_path];
    switchcheck =[plist2 objectForKey:@"switchcheck"];
    swithchcheckint = [switchcheck intValue];

    if(swithchcheckint==1)
    {
        message102 =@"111";
    }
    else if(swithchcheckint==0)
    {
        message102 =@"110";
    }
    //---convert an NSString object to NSData---
    NSData* data;
     [messageTextField setText:message102];
     data = [message102 dataUsingEncoding:NSUTF8StringEncoding];
    [self mySendDataToPeers:data:peerID];
}


@end

Please someone help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:54:16+00:00Added an answer on June 11, 2026 at 7:54 pm

    Apple only allow background processing of an app to occur for 10 minutes (this used to be just 5), unless the app is either music, VOIP or navigational, in which case you will need to specify in your Plist file.

    This is why you app stops after 10 minutes, by default Xcode will continue running the app as you are debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am in the process of creating a java application that will be running
I am creating an winform application that will run on a tablet PC. One
I am creating a forecasting application that will run simulations for various modes that
I'm creating an application that will run code in a sandboxed environment. This environment
I will be creating an Application that will be showing the Products in a
I am creating an application that will have a list of items that can
I'm creating an application that will store geolocation data for specific transactions. Should I
I am creating a web application that will have many users. Each user has
I am creating a Java application that will take in .tar files and retrieve
I'm currently creating an MVC application that will likely to expand to include a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.