문제

내 응용 프로그램에는 인터넷 연결이 필요합니다. iPhone 유휴 상태를 잠시 동안 유지하면 3G 연결이 종료되는 것 같습니다. 잠에서 깨우고 (잠금 해제를 위해 슬라이드) 응용 프로그램을 실행하면 인터넷에 연결할 수 없습니다. YouTube 또는 Safari를 먼저 실행 한 다음 인터넷 연결을받은 다음 YouTube/ Safari를 종료 한 다음 응용 프로그램을 사용하여 서비스에 로그인 할 수 있습니다.

응용 프로그램에서 3G 연결을 어떻게 활성화 할 수 있는지 알려 주시겠습니까 (유휴 상태에서 깨어 난 직후 응용 프로그램을 사용할 수 있고 YouTube/ Safari와 같은 다른 응용 프로그램을 실행할 필요가 없습니까?

감사.

도움이 되었습니까?

해결책

유휴 타이머를 비활성화하려면 IdletimerDisabled 속성 UIAPPLICATION 클래스의.

Apple에서 :

이 속성의 기본값은 아니오입니다. 대부분의 애플리케이션이 단기간에 사용자 입력으로 터치하지 않으면 시스템은 장치를 화면이 어두워지는 "수면"상태로 만듭니다. 이것은 전력을 보존하기 위해 수행됩니다. 그러나,이 속성을 예로 설정하여 가속도계 (예 : 게임)를 제외하고는 사용자 입력이없는 응용 프로그램은 "유휴 타이머"를 비활성화하여 시스템 수면을 피할 수 있습니다.

중요 : 필요한 경우에만이 속성을 설정해야하며 더 이상 필요하지 않을 때는 아니오로 재설정해야합니다. 유휴 타이머가 경과 할 때 대부분의 응용 프로그램은 시스템이 화면을 끄도록해야합니다. 여기에는 오디오 애플리케이션이 포함됩니다. 오디오 세션 서비스를 적절하게 사용하면 화면이 꺼지면 재생 및 녹음이 중단되지 않습니다. 유휴 타이머를 비활성화 해야하는 유일한 응용 프로그램은 산발적 인 사용자 상호 작용을 사용하여 애플리케이션, 게임 또는 유사한 프로그램을 매핑하는 것입니다.

다른 팁

There is obviously another better solution, but you could load a blank page with:

[NSString stringWithContentsOfUrl ... ]

The connection will be established if it is necessary.

Only NSURLConnection (and any APIs that are layered on top of it) reinitializes the data connection after waking from sleep. To reinitialize the data connection create a dummy NSURLConnection to a non-local address and cancel it right away; then the socket API will work as expected.

There is a post on the developer forums where an Apple dev explains this in detail (but I can't find it at the moment)

Are you sure you're establising the connection correctly? My application does the same using sockets and it has no problems to re-establish the connection after device sleep. Use Reachability API in SystemConfiguration framework to get notified when coverage is available and after that make your connection attempt. Note that a time period - from several seconds to couple of minutes - has to elapse after the device awakes to gain Internet connectivity, so be patient.

There is Reachability sample from Apple, search also stackoverflow for reachability and you'll find more hints how to implement it.

Actually, you get the same problem when you change the network settings on your phone between launches of the application. For instance let's say that you use the WIFI connection when you launch the app. Then you close the app and switch off the WIFI so that the device uses the carrier's network. When you relaunch the app the socket won't be able to connect unless you do the trick with the dummy NSURLConnection (or you launch the browser before lanuching the app).

Also, canceling the NSURLConnection right after initializing it (with connectionWithRequest or initWithRequest) did not work for me. Either do not cancel the request or wait some time before canceling it (e.g. with performSelector:withObject:afterDelay:).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top