自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone網(wǎng)絡(luò)軟件在睡眠情況斷線問題解決

移動開發(fā) iOS
iPhone網(wǎng)絡(luò)軟件在睡眠情況斷線問題解決是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)iphone網(wǎng)絡(luò)軟件的使用,具體是如何實(shí)現(xiàn)的了,來考哪本文詳細(xì)內(nèi)容。

iPhone網(wǎng)絡(luò)軟件在睡眠情況斷線問題解決是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)iphone網(wǎng)絡(luò)軟件的使用。如果你希望使用iPhone的網(wǎng)絡(luò)功能并保持長連接,并使用Wifi的話,你可能會發(fā)現(xiàn)一個問題,那就是在iPhone處于睡眠狀態(tài)時,Wifi會中斷,這樣程序就無法保持連接。(iPhone非官方SDK)

下面的代碼可能會幫你解決這個問題。

以下代碼摘自MobileChat:

首先在applicationDidFinishLaunching方法中添加以下代碼:

  1. IONotificationPortRef notificationPort;  
  2.  
  3. root_port = IORegisterForSystemPower(self, &notificationPort, powerCallback, &notifier);  
  4.  
  5. CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notificationPor t), kCFRunLoopCommonModes);  

接著添加如下全局方法(在所有類之外添加)

  1. void powerCallback(void *refCon, io_service_t service, natural_t messageType, void *messageArgument) {  
  2. [(YourAppnameApp*)refCon powerMessageReceived: messageType withArgument: messageArgument];  
  3. }  

在你的程序里添加下面的代碼:

  1. - (void)powerMessageReceived:(natural_t)messageType withArgument:(void *) messageArgument {  
  2. switch (messageType) {  
  3. case kIOMessageSystemWillSleep:  
  4. IOAllowPowerChange(root_port, (long)messageArgument);   
  5. break;  
  6. case kIOMessageCanSystemSleep:  
  7. //if([self wifiKeepAliveIsSet]) {  
  8. IOCancelPowerChange(root_port, (long)messageArgument);  
  9. //}  
  10. break;   
  11. case kIOMessageSystemHasPoweredOn:  
  12. break;  
  13. }  

這樣就可以保持iPhone在網(wǎng)絡(luò)連接的狀況下不睡眠了(當(dāng)然,可能會比較費(fèi)電 ^_^)。

小結(jié):iPhone網(wǎng)絡(luò)軟件在睡眠情況斷線問題解決的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!

責(zé)任編輯:zhaolei 來源: 網(wǎng)易博客
相關(guān)推薦

2011-07-20 16:52:26

iPhone 網(wǎng)絡(luò) 睡眠

2018-10-22 14:19:52

網(wǎng)絡(luò)組建網(wǎng)絡(luò)網(wǎng)絡(luò)管理

2011-06-27 16:44:59

Qmake

2011-06-13 16:16:32

Qt 中文問題

2011-08-10 14:29:08

2010-06-17 11:35:24

Ubuntu 修復(fù)Gr

2010-04-28 18:01:15

Unix系統(tǒng)

2015-07-28 11:29:01

網(wǎng)絡(luò)軟件

2011-09-07 17:41:01

ubunturvm

2009-06-03 15:50:51

eclipse中啟動超eclipsetomcat

2011-08-03 11:07:01

布線管理軟件

2011-09-06 09:26:03

2011-11-28 22:45:19

Nginxsession

2009-12-28 10:56:45

WPF Image

2010-05-05 10:25:24

Unix操作系統(tǒng)

2010-05-05 14:20:46

AIX CDE

2012-05-09 10:08:41

跨機(jī)房

2011-01-21 14:13:10

2011-07-27 15:03:54

iPhone 升級 編譯

2009-06-30 14:02:00

Struts亂碼Eclipse
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號