iOS開(kāi)發(fā)——ios10以后應(yīng)用內(nèi)跳轉(zhuǎn)系統(tǒng)設(shè)置頁(yè)面無(wú)效的解決辦法

需求

應(yīng)用需要定位服務(wù),如果系統(tǒng)定位服務(wù)未開(kāi)啟,就要跳到系統(tǒng)設(shè)置頁(yè)面。

問(wèn)題

關(guān)于如何跳轉(zhuǎn),網(wǎng)上有很多好的文章,這里就不贅述了,貼出幾個(gè)鏈接:
1、http://www.itdecent.cn/p/767c409c50e6
2、http://www.2cto.com/kf/201506/405779.html
3、http://blog.csdn.net/wuyanyanstrong/article/details/51149786
4、http://blog.csdn.net/wlm0813/article/details/54896499
等。。。
但是,ios10以后,只能跳到系統(tǒng)設(shè)置里自己應(yīng)用的配置界面,如下

自己應(yīng)用的設(shè)置

而無(wú)法跳轉(zhuǎn)到系統(tǒng)總體的設(shè)置頁(yè)面,如下
系統(tǒng)設(shè)置

解決方法

利用一個(gè)私有API,需要用到的類(lèi):LSApplicationWorkspace,屬于MobileCoreServices.framework靜態(tài)庫(kù),關(guān)于這一私有API和runtime的知識(shí)可以查看:http://www.itdecent.cn/p/6167b9ce7af8
代碼

NSString *defaultWork = @"defaultWorkspace";
NSString *bluetoothMethod = @"openSensitiveURL:withOptions:";
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];

這樣就可以跳轉(zhuǎn)到系統(tǒng)設(shè)置頁(yè)面了。

備注

1、這樣跳轉(zhuǎn),不是跳轉(zhuǎn)到系統(tǒng)設(shè)置主頁(yè)面,系統(tǒng)設(shè)置頁(yè)面本身在哪個(gè)頁(yè)面,跳轉(zhuǎn)過(guò)去,頁(yè)面會(huì)保持在那個(gè)頁(yè)面,例如你之前操作手機(jī)打開(kāi)了wifi設(shè)置,跳轉(zhuǎn)過(guò)去就是在wifi設(shè)置;
2、根據(jù)我所掌握的知識(shí),ios10之后,沒(méi)有辦法指定跳轉(zhuǎn)的具體位置,例如你想指定跳轉(zhuǎn)到系統(tǒng)設(shè)置的藍(lán)牙設(shè)置,ios10以后做不到,如果有會(huì)的大神朋友請(qǐng)給我留言!
3、上面的代碼中,@"defaultWorkspace",@"openSensitiveURL:withOptions:"這些字比較敏感,可能會(huì)影響審核,可以采取NSData轉(zhuǎn)NSString的方式,屏蔽掉那些字段

//@"defaultWorkspace"
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 *defaultWork = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
//@"openSensitiveURL:withOptions:"
NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];
NSString *keyTwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];
NSData *dataThree = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];
NSString *keyThree = [[NSString alloc] initWithData:dataThree encoding:NSASCIIStringEncoding];
NSString *bluetoothMethod = [NSString stringWithFormat:@"%@%@%@%@",keyTwo,@":",keyThree,@":"];
//私有API跳轉(zhuǎn)
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)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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