
在不彈出網(wǎng)絡(luò)授權(quán)提示的設(shè)備中,更有些機(jī)型會(huì)默認(rèn)不允許訪問(wèn)網(wǎng)絡(luò)。那么,坑就來(lái)了。導(dǎo)致APP數(shù)據(jù)加載不出來(lái),而用戶(hù)又不知道是網(wǎng)絡(luò)問(wèn)題。
在網(wǎng)上查到:
??????據(jù)了解,這一功能與工信部起草的一份《移動(dòng)智能終端應(yīng)用軟件(APP)預(yù)置和分發(fā)管理暫行規(guī)定》有關(guān),規(guī)定中要求設(shè)備生產(chǎn)企業(yè)「未經(jīng)明示且經(jīng)用戶(hù)同意,不得實(shí)施擅自收集使用用戶(hù)個(gè)人信息、強(qiáng)制開(kāi)啟應(yīng)用軟件……等侵害用戶(hù)合法權(quán)益和危害網(wǎng)絡(luò)安全的行為」。
??????所以現(xiàn)在我們使用的國(guó)行手機(jī),首次打開(kāi) App,一般也都會(huì)有請(qǐng)求網(wǎng)絡(luò)權(quán)限的彈窗。非國(guó)行設(shè)備新安裝的 App 不會(huì)彈出「請(qǐng)求聯(lián)網(wǎng)」的授權(quán)提示。
查看是否國(guó)行手機(jī)可以在 設(shè)置->通用->關(guān)于本機(jī)->型號(hào) 中查看,CH為國(guó)行、ZP為港行、LL為美行、KR為韓行、J為日行。
但是,目前的「聯(lián)網(wǎng)權(quán)限」功能并不完善,還因此帶來(lái)了一些使用上的不便。具體表現(xiàn)為:在部分國(guó)行 iPhone 上,當(dāng)用戶(hù)打開(kāi)一款新 App 時(shí),請(qǐng)求聯(lián)網(wǎng)授權(quán)的提示框有一定幾率不會(huì)出現(xiàn)。這就出現(xiàn)了 App 加載異常,用戶(hù)又不知道這是因?yàn)闆](méi)有聯(lián)網(wǎng)導(dǎo)致APP無(wú)法使用的,畢竟其他軟件是可以上網(wǎng)的。
所以,針對(duì)這種情況,APP端最好做一下網(wǎng)絡(luò)授權(quán)判斷。上代碼:
#import <CoreTelephony/CTCellularData.h>
#pragma mark - Network auth status
- (void)networkAuthStatus {
CTCellularData *cellularData = [[CTCellularData alloc]init];
cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state) {
if (state == kCTCellularDataRestricted) {
//拒絕
[self networkSettingAlert];
} else if (state == kCTCellularDataNotRestricted) {
//允許
} else {
//未知
[self unknownNetwork];
}
};
}
- (void)networkSettingAlert {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"您尚未授權(quán)“app”訪問(wèn)網(wǎng)絡(luò)的權(quán)限,請(qǐng)前往設(shè)置開(kāi)啟網(wǎng)絡(luò)授權(quán)" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"去設(shè)置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
}]];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
});
}
- (void)unknownNetwork {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"未知網(wǎng)絡(luò)" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
});
}