乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      iOS設(shè)備中WiFi、藍(lán)牙和飛行模式的開啟與關(guān)閉

       現(xiàn)在決定明天 2014-03-11

      轉(zhuǎn)自:http://blog.csdn.net/cssmhyl/article/details/7963537

      今天寫了一段有關(guān)在iPhone程序中開關(guān)WiFi型號(hào)的代碼,經(jīng)測試運(yùn)行良好。

      我想不用我多說大家都應(yīng)該知道以上的功能只能在越獄的設(shè)備中實(shí)現(xiàn)!

      好了,閑話稍少敘,進(jìn)入正題:

      1.首先要在SpringBoard啟動(dòng)之后,我們要執(zhí)行hook動(dòng)作:

        NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
            if ([identifier isEqualToString:@"com.apple.springboard"]) {
                Class $SpringBoard = (objc_getClass("SpringBoard"));
                _SpringBoard$applicationDidFinishLaunching$ = MSHookMessage($SpringBoard, @selector(applicationDidFinishLaunching:), &$SpringBoard$applicationDidFinishLaunching$);
            }

      2. 然后實(shí)現(xiàn)我們的HOOK函數(shù),這里我們僅僅是注冊(cè)了兩個(gè)消息:

        CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL,
                                          &NotificationReceivedCallback, CFSTR("turnOffWiFi"), NULL, 
                                          CFNotificationSuspensionBehaviorCoalesce);
          CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL,
                                          &NotificationReceivedCallback, CFSTR("turnOnWiFi"), NULL,
                                          CFNotificationSuspensionBehaviorCoalesce);

      3. 最后我們要響應(yīng)這兩個(gè)信號(hào),也就是實(shí)現(xiàn)我們?cè)诘诙街兄该鞯哪莻€(gè)回調(diào)方法(NotificationReceivedCallback)

      static void NotificationReceivedCallback(CFNotificationCenterRef center, 
                                               void *observer, CFStringRef name, 
                                               const void *object, CFDictionaryRef 
                                               userInfo) 
      {
          BOOL offOrOn = YES;
          if ([(NSString *)name isEqualToString:@"turnOffWiFi"]) {
              offOrOn = NO;
          } else if ([(NSString *)name isEqualToString:@"turnOnWiFi"]) {
              offOrOn = YES;
          }
          [[objc_getClass("SBWiFiManager") sharedInstance] setWiFiEnabled:offOrOn];
      }

      也就是這一步正真的對(duì)WiFi信號(hào)進(jìn)行開關(guān)操作。好了我們的后臺(tái)程序(dynamicLibrary)已經(jīng)編寫完成了。

      然后在我們的前臺(tái)程序中我們找個(gè)事件來發(fā)送我們?cè)诤笈_(tái)注冊(cè)的那兩個(gè)消息,例如一個(gè)Button和一個(gè)BOOL值來完成這功能:

       BOOL turnOff = YES;
          if (turnOn) {
                      CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("turnOffWiFi"), NULL, NULL, 0);
          } else {
                      CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("turnOffWiFi"), NULL, NULL, 0);

          }

      測試設(shè)備:iPhone 3GS

      系統(tǒng):iOS 4.3.3

      設(shè)備狀態(tài):已越獄

      測試結(jié)果:Perfect!

       

      注1:使用相同的方法我們可以啟動(dòng)和關(guān)閉藍(lán)牙:

      首先,我們要從BluetoothManager.framework這個(gè)私有庫中dump出BluetoothManager這個(gè)類;

      然后,我們就可以調(diào)用這個(gè)類的setPowered:方法啟動(dòng)和關(guān)閉藍(lán)牙了(參數(shù):YES為啟動(dòng)、NO為關(guān)閉)。

      帶有.h文件的BluetoothManager.framework請(qǐng)到我的資源里下載

      1. [cpp] view plaincopyprint?  
      2. #import <UIKit/UIKit.h>    
      3. #import <BluetoothManager/BluetoothManager.h>    
      4. //#import <SpringBoard/SBWiFiManager.h>    
      5.     
      6. @interface hylViewController : UIViewController{    
      7.     BOOL isBlueToothOn;    
      8.     BOOL isWlanOn;    
      9. }    
      10.     
      11. @end    


      1. #import "hylViewController.h"    
      2.     
      3. @implementation hylViewController    
      4. #pragma mark - View lifecycle    
      5. - (void)viewDidLoad    
      6. {    
      7.     [super viewDidLoad];    
      8.     
      9. Class BluetoothManager = objc_getClass( "BluetoothManager" ) ;    
      10.     id btCont = [BluetoothManager sharedInstance] ;    
      11.     isBlueToothOn = [btCont enabled] ;    
      12. UISwitch *blueTouthSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(150,50,0,0)];    
      13.     [blueTouthSwitch addTarget:self action:@selector(BlueTouthSwitchAction:) forControlEvents:UIControlEventValueChanged];    
      14.     blueTouthSwitch.on = isBlueToothOn;    
      15.     [self.view addSubview:blueTouthSwitch];    
      16.     [blueTouthSwitch release];    
      17. }    
      18.     
      19. -(void)BlueTouthSwitchAction:(id)sender    
      20. {    
      21.     #if TARGET_IPHONE_SIMULATOR    
      22.         exit( EXIT_SUCCESS ) ;    
      23.     #else    
      24.         /* this works in iOS 4.2.3 */    
      25.         Class BluetoothManager = objc_getClass( "BluetoothManager" );    
      26.         id btCont = [BluetoothManager sharedInstance];    
      27.         [self performSelector:@selector(toggle:) withObject:btCont afterDelay:1.0f];    
      28.     #endif    
      29. }    
      30. #if TARGET_IPHONE_SIMULATOR    
      31. #else    
      32. - (void)toggle:(id)btCont    
      33. {    
      34.         BOOL currentState = [btCont enabled] ;    
      35.         [btCont setEnabled:!currentState] ;    
      36.         [btCont setPowered:!currentState] ;    
      37. }    
      38. #endif    
      39. @end    

      經(jīng)過我的測試是可以正常使用的。

      注2:我們同樣可以對(duì)飛行模式作開啟和關(guān)閉操作:

      首先:我們從SpringBoard中可以dump出SBTelephonyManager和SBStatusBarDataManager這兩個(gè) 類,前者主要負(fù)責(zé)功能的開關(guān),后者則是負(fù)責(zé)UI顯示的。使用SBTelephonyManager的isInAirplaneMode方法可以得到當(dāng)前的 飛行模式狀態(tài),setIsInAirplaneMode:這個(gè)方法來設(shè)置飛行模式。使用SBStatusBarDataManager的 airplaneModeChanged和_updateSignalStrengthItem來刷新UI顯示狀態(tài)。



        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多