萤石云 iOSSDK,移植跨平台相关工程
JLChen
2021-02-02 9100afbe1805413504840e6957097be638579045
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
//  EZLocationAlertVCViewController.m
//  EZOpenSDKDemo
//
//  Created by yuqian on 2019/9/19.
//  Copyright © 2019 Ezviz. All rights reserved.
//
 
#import "EZLocationAlertVCViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "EZWifiInfoViewController.h"
#import "Masonry.h"
 
 
@interface EZLocationAlertVCViewController ()<CLLocationManagerDelegate>
 
@property (nonatomic, strong) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) IBOutlet UILabel *connectLabel;
@property (nonatomic, strong) IBOutlet UIButton *btn;
@property (nonatomic, strong) IBOutlet UIButton *exceptionButton;
@property (nonatomic, strong) CLLocationManager *locationmanager;
 
@end
 
@implementation EZLocationAlertVCViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    [self layoutSubView];
    
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
        _locationmanager = [[CLLocationManager alloc]init];
        _locationmanager.delegate = self;
        [_locationmanager requestWhenInUseAuthorization];
    }
}
 
- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(appDidBecomeActive)
                                                 name:UIApplicationWillEnterForegroundNotification
                                               object:nil];
}
 
- (void) viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
 
- (void)onClick
{
    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if([[UIApplication sharedApplication] canOpenURL:url])
    {
        //TODO:版本适配
        [[UIApplication sharedApplication] openURL:url];
    }
}
 
- (void)appDidBecomeActive
{
    if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusRestricted)
    {
         [self performSegueWithIdentifier:@"go2WifiInfo" sender:nil];
    }
}
 
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways) {
        [self performSegueWithIdentifier:@"go2WifiInfo" sender:nil];
    }
}
 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
    if ([[segue destinationViewController] isKindOfClass:[EZWifiInfoViewController class]]) {
        EZWifiInfoViewController *vc = (EZWifiInfoViewController *)[segue destinationViewController];
        vc.supportApMode = self.supportApMode;
        vc.supportSmartMode = self.supportSmartMode;
        vc.supportSoundMode = self.supportSoundMode;
    }
}
 
- (void)exceptionButtonClicked:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
 
- (void) setupUI {
    
    self.title = NSLocalizedString(@"请开启定位服务", );
    
    _imageView.image = [UIImage imageNamed:@"icn_location"];
    _imageView.contentMode = UIViewContentModeScaleToFill;
    
    _connectLabel.text = NSLocalizedString(@"定位服务未开启,请进入系统[设置]> [隐私] > [定位服务]中打开开关,并允许使用定位服务",);
    _connectLabel.numberOfLines = 0;
    _connectLabel.textColor = [UIColor blackColor];
    _connectLabel.textAlignment = NSTextAlignmentCenter;
    _connectLabel.font = [UIFont systemFontOfSize:13.0];
    
    [_btn setTitle:NSLocalizedString(@"立即开启",) forState:UIControlStateNormal];
    [_btn setTintColor:[UIColor whiteColor]];
    [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btn.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [_btn addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside];
    _btn.backgroundColor = [UIColor orangeColor];
    _btn.layer.cornerRadius = 22;
    _btn.clipsToBounds = YES;
    
    [_exceptionButton addTarget:self action:@selector(exceptionButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UILabel *label = [[UILabel alloc] init];
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 2;
    [_exceptionButton addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_exceptionButton);
    }];
    
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"暂不",)];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, attributeStr.length)];
    [attributeStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15.f] range:NSMakeRange(0, attributeStr.length)];
    [attributeStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, attributeStr.length)];
    label.attributedText = attributeStr;
}
 
- (void)layoutSubView
{
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(100);
    }];
    
    [_connectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_imageView.mas_bottom).offset(50);
        make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width-40);
    }];
    
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_connectLabel.mas_bottom).offset(40);
        make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width-40);
        make.height.mas_equalTo(44);
    }];
    
    [_exceptionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(_btn.mas_bottom).offset(15);
    }];
}
 
@end