萤石云 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
//
//  EZEditViewController.m
//  EZOpenSDKDemo
//
//  Created by DeJohn Dong on 15/12/16.
//  Copyright © 2015年 Ezviz. All rights reserved.
//
 
#import "EZEditViewController.h"
#import "DDKit.h"
 
 
@interface EZEditViewController ()<UITextFieldDelegate>
 
@property (nonatomic, weak) IBOutlet UITextField *deviceNameTextField;
 
@end
 
@implementation EZEditViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = NSLocalizedString(@"device_modify_name_title", @"修改设备名称");
    self.deviceNameTextField.text = self.deviceInfo.deviceName;
//
//    self.deviceNameTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 30)];
//    self.deviceNameTextField.leftViewMode = UITextFieldViewModeAlways;
//    [self.deviceNameTextField dd_addSeparatorWithType:ViewSeparatorTypeVerticalSide];
}
 
- (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.
}
*/
 
#pragma mark - UITextFieldDelegate Methods
 
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (self.deviceNameTextField == textField)
    {
        NSString *strTemp = [NSString stringWithFormat:@"%@%@", textField.text, string];
        if ([self convertToInt:strTemp] > 50)
        {
            return NO;
        }
        
        return YES;
    }
    return YES;
}
 
#pragma mark - Action Methods
 
- (int)convertToInt:(NSString *)strtemp
{
    int strlength = 0;
    char *p = (char *)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
    for (int i = 0; i < [strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++) {
        if (*p)
        {
            p++;
            strlength++;
        }
        else
        {
            p++;
        }
    }
    return (strlength + 1)/2;
}
 
- (IBAction)saveName:(id)sender
{
    [EZOPENSDK setDeviceName:self.deviceNameTextField.text
                deviceSerial:self.deviceInfo.deviceSerial
                  completion:^(NSError *error) {
                      NSLog(@"error = %@",error);
                      if(!error)
                      {
                          self.deviceInfo.deviceName = self.deviceNameTextField.text;
                          [self.navigationController popViewControllerAnimated:YES];
                      }
                  }];
}
 
@end