2013-03-07 4 views
1

홈 버튼을 누르고 응용 프로그램이 백그라운드로 들어가면 이미지를 업로드하고 싶습니다. 가능합니까? 그렇다면 어떻게? 그리고 만약 그렇다면 다른 대안이 있습니까? 당신은 특정 시간 -응용 프로그램이 백그라운드에서 실행될 때 webRequest를 호출 할 수 있습니까?

UIBackgroundTaskIdentifier bgTask = 0; 
    UIApplication *app = [UIApplication sharedApplication]; 
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
     [app endBackgroundTask:bgTask]; 
    }]; 
    self.silenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self 
                 selector:@selector(startLocationServices) userInfo:nil repeats:YES]; 

이 코드를 사용하여 백그라운드에서 작업을 수행 할 수 있습니다

+0

로 이동 http://developer.apple.com/library/ios/#technotes /tn2277/_index.html – Desdenova

답변

3

사전에 덕분에 ...이를 참조하십시오 http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

내가이 유 도움이 될 것입니다 생각합니다. :)

+0

고맙습니다 .... 사과 응용 프로그램을 읽고 응용 프로그램이 백그라운드로 이동 한 후 업로드 프로세스가 최대 10 분 동안 실행될 수 있다고 결론을 내었습니다 –

+0

환영 @KhushbuPatel .. 해피 코딩 :) – shivam

1

앱은 장시간 실행되는 작업을 마칠 수 있도록 닫힌 후 최대 10 분 동안 백그라운드에서 실행되도록 요청할 수 있습니다. 일부 프로세스 만 백그라운드에서 실행할 수 있습니다. 참조 구현 장기 실행 배경 작업 섹션 in this reference.

앱이 너무 허용되면, 당신은 코드 아래에 시도 할 수 있습니다 :

- (void)applicationDidEnterBackground:(UIApplication *)application 

{ 

    UIBackgroundTaskIdentifier bgTask; 
    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{ 

     // Clean up any unfinished task business by marking where you 

     // stopped or ending the task outright. 

     [application endBackgroundTask:bgTask]; 

     bgTask = UIBackgroundTaskInvalid; 

    }]; 



    // Start the long-running task and return immediately. 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 



     // Do the work associated with the task, preferably in chunks. 



     [application endBackgroundTask:bgTask]; 

     bgTask = UIBackgroundTaskInvalid; 

    }); 

} 

를 앱이

을 실행하는 왼쪽 얼마나 많은 시간을 알고 싶다면 더 타이밍에서
NSTimeInterval ti = [[UIApplication sharedApplication]backgroundTimeRemaining]; 
NSLog(@"Remaining Time: %f", ti); // just for debug 

reference PDF(page 60)

관련 문제