현재 응용 프로그램에서 매 시간 TCP 연결을 통해 서버에 폴링해야합니다. 가장 좋은 옵션 중 하나가 서버 측에서 푸시 알림을 사용하는 것임을 알고 있지만 그렇게 할 수는 없습니다. 그래서 현재 9 분마다 발사하는 타이머를 사용하여 백그라운드에서 앱을 계속 실행합니다. 이 작품은 잘 .. 시간에 나는 서버에 투표를 호출합니다.매시간 Poll to TCP 서버 ios
Tcp 연결이 열리고 폴링 데이터가 생성되지만 서버로부터 응답이 없습니다. 백그라운드에서 앱이 몇 초의 시간을 필요로하는 코드 블록을 실행할 수 없기 때문입니까?
NSData *data = [[NSData alloc] initWithData:[string dataUsingEncoding:NSASCIIStringEncoding]];
[_cacheArray addObject:string];
[_outputStream write:[data bytes] maxLength:[data length]];
그리고 마지막으로 streamDidReturn :
-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
NSLog(@"event number %i ", eventCode);
switch (eventCode)
{
case NSStreamEventOpenCompleted:
NSLog(@"Stream opened");
break;
case NSStreamEventHasBytesAvailable:
if (aStream == _inputStream)
{
uint8_t buffer[1024];
int len;
while ([_inputStream hasBytesAvailable])
{
len = [_inputStream read:buffer maxLength:sizeof(buffer)];
if (len > 0)
{
NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
if (nil != output)
NSLog(@"server said: %@", output);
}
}
}
break;
case NSStreamEventErrorOccurred:
break;
case NSStreamEventEndEncountered:
break;
case NSStreamEventHasSpaceAvailable:
NSLog(@"space available");
break;
default:
NSLog(@"Unknown event");
}
}
공간을 어떤 도움을 크게, 아픈, 너무 아래의 일부 코드를 게시
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
{
//Check if our iOS version supports multitasking I.E iOS 4
if ([[UIDevice currentDevice] isMultitaskingSupported])
{
//Check if device supports mulitasking
UIApplication *application = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier background_task;
background_task = [application beginBackgroundTaskWithExpirationHandler:^{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];
ViewController *controller = (ViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"viewController"];
[controller sendPoll];
});
}
}
다음 코드는 출력 데이터를 쓸 주시면 감사하겠습니다 사용할 수 있지만 서버에서 더 이상 아무것도 얻을 수 없습니다.
만 음악, 위치, 또는 음성 IP 문제를 정리, 당신은하지 않는 폴링, 배경에서 실행할 수 없습니다 허용 응용 프로그램이 실행 중입니다. 이러한 백그라운드 작업에 등록하고 다른 작업을하면 Apple이 귀하의 응용 프로그램을보고 거부합니다. – Jano
Yeap thats algood thanks Jano, 응용 프로그램은 위치 서비스를 사용하여 서버로 폴링하는 데 사용 된 10 초 동안 앱을 유지합니다. 또한 gps 데이터를 서버로 전송합니다. 다행히 사과는 그것을 받아 들일만큼 관련성이 높습니다. 그렇지 않으면 푸시 알림은 –