美文网首页
iOS 权限集合和跳转手机系统设置界面and应用设置界面

iOS 权限集合和跳转手机系统设置界面and应用设置界面

作者: XP_Swf | 来源:发表于2017-03-24 10:22 被阅读0次

    info.plist 中添加:⬇️

    <key>NSCameraUsageDescription</key>

    <string>需要相机权限</string>

    <key>NSLocationWhenInUseUsageDescriptionNSMicrophoneUsageDescription</key>

    <string>需要麦克风权限</string>

    <key>NSPhotoLibraryUsageDescription</key>

    <string>需要照片权限</string>


    didFinishLaunchingWithOptions:⬇️ 启动的时候添加弹窗提示用户开启权限

    #if !TARGET_IPHONE_SIMULATOR

    //iOS8 注册APNS

    if ([[UIApplication sharedApplication]  respondsToSelector:@selector(registerForRemoteNotifications)]) {

    [[UIApplication sharedApplication]  registerForRemoteNotifications];

    UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge |

    UIUserNotificationTypeSound |

    UIUserNotificationTypeAlert;

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];

    [[UIApplication sharedApplication]  registerUserNotificationSettings:settings];

    }

    #endif

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0 ;

    //相册

    if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusNotDetermined) {

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

    if (status == PHAuthorizationStatusAuthorized) {

    }

    }];

    }



    跳转至APP的系统设置界面


    NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

    if([[UIApplication sharedApplication] canOpenURL:url]) {

    NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];

    [[UIApplication sharedApplication] openURL:url];

    }

    跳转至手机系统设置界面

    NSString * defaultWork = [self getDefaultWork];

    NSString * bluetoothMethod = [self getBluetoothMethod];

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

    Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");

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

    -(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;

    }

    -(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;

    }


    检测用户是否开启消息推送权限:

    UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];

    if (UIUserNotificationTypeNone == setting.types) {

    没开启

    }else{

    开启

    }

    相关文章

      网友评论

          本文标题:iOS 权限集合和跳转手机系统设置界面and应用设置界面

          本文链接:https://www.haomeiwen.com/subject/pibxottx.html