IVTNewMessageRemindViewController.m 4.11 KB
//
//  IVTNewMessageRemindViewController.m
//  IVTMeLiveTwo
//
//  Created by XRG on 16/8/23.
//  Copyright © 2016年 QLQ. All rights reserved.
//

#import "IVTNewMessageRemindViewController.h"

@interface IVTNewMessageRemindViewController ()
{
    UIImageView *bgImageView;
    UILabel *messageText;
    UISwitch *messageRemindSwitch;
    UIButton *goSettingButton;
}
@end

@implementation IVTNewMessageRemindViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setNavigationBar];
    
    bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的--第一个背景条"]];
    bgImageView.userInteractionEnabled = YES;
    bgImageView.frame = CGRectMake(0, 10, kScreenWidth, 44);
    [self.view addSubview:bgImageView];
    
    messageText = [[UILabel alloc] init];
    messageText.font = [UIFont IVTH3Font];
    messageText.textAlignment = 1;
    messageText.text = @"直播消息提醒";
    messageText.textColor = [UIColor IVTMainTextColor];
    [bgImageView addSubview:messageText];
    [messageText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgImageView).offset(5);
        make.left.equalTo(bgImageView).offset(10);
        make.size.mas_equalTo(CGSizeMake(120, 30));
    }];
    
    messageRemindSwitch = [[UISwitch alloc] init];
    messageRemindSwitch.onTintColor = [UIColor YXColorWithHexCode:@"D31863"];
    if ([self isAllowedNotification]) {
        messageRemindSwitch.on = YES;
    }
    else{
        messageRemindSwitch.on = NO;
    }
    //    [_MessageRemindSwitch addTarget:self action:@selector(switchNotification:) forControlEvents:UIControlEventValueChanged];
    [bgImageView addSubview:messageRemindSwitch];
    [messageRemindSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgImageView).offset(5);
        make.right.equalTo(bgImageView).offset(-20);
    }];
    
    goSettingButton = [UIButton buttonWithType:UIButtonTypeCustom];
    goSettingButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [goSettingButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [goSettingButton setTitle:@"请在iPhone的“设置”-“通知”中进行修改。" forState:UIControlStateNormal];
    [goSettingButton addTarget:self action:@selector(doSettingButton) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:goSettingButton];
    [goSettingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgImageView.mas_bottom).offset(5);
        make.left.equalTo(bgImageView.mas_left).offset(5);
        make.right.equalTo(bgImageView.mas_right).offset(-10);
        make.height.mas_equalTo(40);
    }];

}

- (void)setNavigationBar{
    self.navigationItem.title = @"新消息提醒";
}

- (void)doSettingButton{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}

//- (void)switchNotification:(id)sender
//{
//    UISwitch *switchButton = (UISwitch*)sender;
//    BOOL isButtonOn = [switchButton isOn];
//    if (isButtonOn) {
//            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
////        NSURL*url=[NSURL URLWithString:@"prefs:root=NOTIFICATIONS_ID"];
////        [[UIApplication sharedApplication] openURL:url];
//    }else {
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
//    }
//}

- (BOOL)isAllowedNotification {
    UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
    if (UIUserNotificationTypeNone != setting.types) {
        return YES;
    }
    return NO;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end