有個項目需要研究非ios裝置與ios裝置的串連,之前瞭解到蘋果的官方api是不支援這個操作的,於是便開始研究蘋果的私人api。
在cc上也有很多文章討論過,但始終沒什麼實質性進展。
本人經過一番google,成功使用私人api開啟了iphone的藍芽。現在把方法分享出來,希望能給大家提供一些思路。
1.首先在/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/PrivateFrameworks路徑下找到BluetoothManager.framework(如果我沒估計錯的話,裡面只有一個庫檔案,沒有標頭檔)
2. 所需的標頭檔,手動添加到BluetoothManager.framework中,並建立一個Headers檔案夾。
3.建立一個工程將以上路徑下的BluetoothManager.framework添加到工程中
4.將以下代碼添加到工程中。(注意:不需要引入BluetoothManager的標頭檔,否則會出現編譯錯誤)
-(void)startBluetooth{
#if TARGET_IPHONE_SIMULATOR
exit( EXIT_SUCCESS ) ;
#else
/* this works in iOS 4.2.3 */
Class BluetoothManager = objc_getClass( "BluetoothManager" ) ;
id btCont = [BluetoothManager sharedInstance] ;
[self performSelector:@selector(toggle:) withObject:btCont afterDelay:1.0f] ;
#endif
}
#if TARGET_IPHONE_SIMULATOR
#else
- (void)toggle:(id)btCont
{
BOOL currentState = [btCont enabled] ;
[btCont setEnabled:!currentState] ;
[btCont setPowered:!currentState] ;
}
#endif
5.在真機上編譯運行,會發現iphone的藍芽成功開啟。
但是,遺憾的是,目前我研究出來的只有開啟藍芽,關於裝置匹配,資料轉送方面沒什麼進展。
希望有人能再接再厲,在我的基礎上研究出裝置匹配和資料轉送的方法,分享出來給大家~