iOS10之后跳轉(zhuǎn)到藍(lán)牙設(shè)置

iOS 是之后系統(tǒng)廢棄了一些方法,以前直接用的[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]]方法不行了,查了網(wǎng)上一些資料,把方法轉(zhuǎn)換成ACSII值進(jìn)行拼組是可行的.直接全部拷貝下來(lái),調(diào)用開(kāi)啟藍(lán)牙的方法就行可,具體方法方法如下:

-(NSString *) getBluetoothMethod{

NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];

NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];

NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];

NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];

NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];

return method;

}

//利用ASCII值進(jìn)行拼裝組合方法。這樣可繞過(guò)審核。

-(NSString *) getDefaultWork{

NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65} length:16];

NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];

return method;

}


/**

開(kāi)啟藍(lán)牙

*/

-(void)setBlueTooth {

NSString * defaultWork = [self getDefaultWork];

NSString * bluetoothMethod = [self getBluetoothMethod];

NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];

Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");

[[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容