|
|
@@ -0,0 +1,267 @@
|
|
|
+//
|
|
|
+// SettingsViewController.m
|
|
|
+// 千模
|
|
|
+//
|
|
|
+// Created by Drew on 2018/10/27.
|
|
|
+// Copyright © 2018年 MUMEI. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "SettingsViewController.h"
|
|
|
+#import <AssetsLibrary/AssetsLibrary.h>
|
|
|
+#import <Photos/Photos.h>
|
|
|
+#import "UIImageView+RoundCorner.h"
|
|
|
+#import "TZImageManager.h"
|
|
|
+#import "TZPhotoPreviewController.h"
|
|
|
+#import "TZImagePickerController.h"
|
|
|
+#import "InfoImageViewController.h"
|
|
|
+#import "InfoNickNameViewController.h"
|
|
|
+#import "InfoImageViewController.h"
|
|
|
+#import "InfoNickNameViewController.h"
|
|
|
+#import "InfoPhoneNumViewController.h"
|
|
|
+#import "InfoLevelViewController.h"
|
|
|
+#import "InfoMoneyViewController.h"
|
|
|
+#import "LoginViewController.h"
|
|
|
+
|
|
|
+@interface SettingsViewController () <TZImagePickerControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>{
|
|
|
+ NSString *nickName;
|
|
|
+}
|
|
|
+@property (weak, nonatomic) IBOutlet UIView *section1;
|
|
|
+@property (weak, nonatomic) IBOutlet UIView *section2;
|
|
|
+@property (weak, nonatomic) IBOutlet UIView *section3;
|
|
|
+@property (weak, nonatomic) IBOutlet UIButton *btnLogout;
|
|
|
+@property (weak, nonatomic) IBOutlet UIImageView *avatar;
|
|
|
+@property (weak, nonatomic) IBOutlet UILabel *nickname;
|
|
|
+@property (weak, nonatomic) IBOutlet UILabel *phone;
|
|
|
+
|
|
|
+@property(nonatomic, strong) UIImagePickerController *imagePickerVc;
|
|
|
+@property(nonatomic, copy) NSData *imageData;
|
|
|
+@property(nonatomic, assign) int photoCount;
|
|
|
+@property(nonatomic, assign) int VideoCount;
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation SettingsViewController
|
|
|
+
|
|
|
+- (void)viewDidLoad {
|
|
|
+ [super viewDidLoad];
|
|
|
+ self.navigationItem.title = @"系统设置";
|
|
|
+ UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ btn.frame = CGRectMake(0, 0, 40, 40);
|
|
|
+ [btn setImage:[UIImage imageNamed:@"backBtn"] forState:UIControlStateNormal];
|
|
|
+ btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
|
|
|
+ [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
|
|
|
+ UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
|
|
|
+ nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
|
|
|
+ self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)backClick{
|
|
|
+ [self.navigationController popViewControllerAnimated:YES];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)viewDidLayoutSubviews{
|
|
|
+ [super viewDidLayoutSubviews];
|
|
|
+ self.btnLogout.layer.cornerRadius = 22;
|
|
|
+ self.btnLogout.layer.shadowColor = [UIColor colorWithRed:255/255.0 green:64/255.0 blue:149/255.0 alpha:0.36].CGColor;
|
|
|
+ self.btnLogout.layer.shadowOffset = CGSizeMake(0,8);
|
|
|
+ self.btnLogout.layer.shadowOpacity = 1;
|
|
|
+ self.btnLogout.layer.shadowRadius = 10;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+-(void)viewWillAppear:(BOOL)animated{
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+ [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
|
|
|
+ [self.navigationController.navigationBar setShadowImage:[UIImage new]];
|
|
|
+ [self getInfo];
|
|
|
+}
|
|
|
+
|
|
|
+-(void)viewWillDisappear:(BOOL)animated{
|
|
|
+ [super viewWillDisappear:animated];
|
|
|
+ [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
|
|
|
+ [self.navigationController.navigationBar setShadowImage:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)getInfo {
|
|
|
+ NSString *str = [NSString stringWithFormat:@"%@memberInfo?action=getuserinfo&PK=%@", webURL, [Helper sharedAccount].accid];
|
|
|
+ [[AHHttpManager sharedManager] POST:str parameters:nil success:^(id responseObject) {
|
|
|
+ NSLog(@"%@", responseObject);
|
|
|
+ if ([[responseObject objectForKey:@"msg"] isEqualToString:@"success"]) {
|
|
|
+ NSDictionary *data = responseObject[@"data"];
|
|
|
+ nickName = data[@"pet"];
|
|
|
+ self.nickname.text = data[@"pet"];
|
|
|
+ self.phone.text = data[@"phone"];
|
|
|
+ [self.avatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@", imageURl, data[@"hphoto"]]] placeholderImage:[UIImage imageNamed:@"default_avatar"]];
|
|
|
+ } else {
|
|
|
+ [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
|
|
|
+ }
|
|
|
+ } failure:^(NSError *error) {
|
|
|
+ NSLog(@"error = %@", error);
|
|
|
+ [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)PushInfo {
|
|
|
+ NSString *str = [NSString stringWithFormat:@"%@/upload", webURL];
|
|
|
+ // NSString *str = @"http://192.168.0.113:8080/thmodel/upload";
|
|
|
+ NSLog(@"str = %@", str);
|
|
|
+ // NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=doQryBroke",webURL];
|
|
|
+ AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
|
|
|
+ manger.responseSerializer = [AFHTTPResponseSerializer serializer];
|
|
|
+ manger.requestSerializer = [AFJSONRequestSerializer serializer];
|
|
|
+ manger.securityPolicy.allowInvalidCertificates = YES;
|
|
|
+ NSDictionary *dict = @{@"memberpk": [Helper sharedAccount].accid,
|
|
|
+ @"action": @"hp"
|
|
|
+ };
|
|
|
+ [manger POST:str parameters:dict constructingBodyWithBlock:^(id <AFMultipartFormData> _Nonnull formData) {
|
|
|
+ if (_imageData == NULL) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ NSLog(@"_imageData = %@", _imageData);
|
|
|
+
|
|
|
+ [formData appendPartWithFileData:_imageData name:@"img" fileName:@"111.png" mimeType:@"image/png"];
|
|
|
+ NSLog(@"image = %@", _imageData);
|
|
|
+ }
|
|
|
+ } progress:nil success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {
|
|
|
+ NSLog(@"re = %@", responseObject);
|
|
|
+
|
|
|
+ NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
|
|
|
+ NSString *img = [dic objectForKey:@"img"];
|
|
|
+ [[NIMSDK sharedSDK].userManager updateMyUserInfo:@{@(NIMUserInfoUpdateTagAvatar): [NSString stringWithFormat:@"%@%@", imageURl, img]} completion:nil];
|
|
|
+ NSLog(@"%@", dic);
|
|
|
+ } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {
|
|
|
+
|
|
|
+ }];
|
|
|
+}
|
|
|
+- (IBAction)tapAvatar:(id)sender {
|
|
|
+ UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
+ [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
+ }];
|
|
|
+ }]];
|
|
|
+ [actionSheet addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
+ [self takePhoto];
|
|
|
+ }]];
|
|
|
+ [actionSheet addAction:[UIAlertAction actionWithTitle:@"选择相册照片" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
|
|
+ [self pushImagePickerController];
|
|
|
+ }]];
|
|
|
+ [self presentViewController:actionSheet animated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)logout:(id)sender {
|
|
|
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"确定退出登录?" message:nil preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
|
|
|
+ [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
+ [self setupLoginViewController];
|
|
|
+ [[[NIMSDK sharedSDK] loginManager] logout:^(NSError *error) {
|
|
|
+
|
|
|
+ NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
|
|
|
+ [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
|
|
|
+ }];
|
|
|
+ }]];
|
|
|
+ [self.navigationController presentViewController:alert animated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setupLoginViewController {
|
|
|
+ [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ LoginViewController *loginController = [[LoginViewController alloc] init];
|
|
|
+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:loginController];
|
|
|
+ self.view.window.rootViewController = nav;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma 上传头像
|
|
|
+
|
|
|
+- (void)pushImagePickerController {
|
|
|
+
|
|
|
+ TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:1 delegate:self pushPhotoPickerVc:YES];
|
|
|
+ imagePickerVc.allowPickingGif = NO;
|
|
|
+ imagePickerVc.allowPickingVideo = NO;
|
|
|
+
|
|
|
+ imagePickerVc.allowTakePicture = NO;
|
|
|
+ imagePickerVc.allowCrop = YES;
|
|
|
+
|
|
|
+ // You can get the photos by block, the same as by delegate.
|
|
|
+ // 你可以通过block或者代理,来得到用户选择的照片.
|
|
|
+ [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self presentViewController:imagePickerVc animated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)takePhoto {
|
|
|
+ AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
|
|
+ if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && iOS7Later) {
|
|
|
+ UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"无法使用照相机" message:@"请在iPhone的\"设置-隐私-照片\"选项中,\r允许千模访问你的手机相册" preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ [actionSheet addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
|
|
+ [self dismissViewControllerAnimated:YES completion:^{
|
|
|
+ }];
|
|
|
+ }]];
|
|
|
+ [self presentViewController:actionSheet animated:YES completion:nil];
|
|
|
+ } else { // 调用相机
|
|
|
+ self.imagePickerVc = [[UIImagePickerController alloc] init];
|
|
|
+ self.imagePickerVc.delegate = self;
|
|
|
+ UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
|
|
|
+ self.imagePickerVc.sourceType = sourceType;
|
|
|
+ [self presentViewController:self.imagePickerVc animated:YES completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
|
|
+ if ([picker isKindOfClass:[UIImagePickerController class]]) {
|
|
|
+ [picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
|
|
|
+
|
|
|
+ [picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ NSString *type = info[UIImagePickerControllerMediaType];
|
|
|
+ if ([type isEqualToString:@"public.image"]) {
|
|
|
+ TZImagePickerController *tzImagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
|
|
|
+
|
|
|
+ [tzImagePickerVc showProgressHUD];
|
|
|
+ UIImage *image = info[UIImagePickerControllerOriginalImage];
|
|
|
+ // save photo and get asset / 保存图片,获取到asset
|
|
|
+ [[TZImageManager manager] savePhotoWithImage:image completion:^(NSError *error) {
|
|
|
+ if (error) {
|
|
|
+ [tzImagePickerVc hideProgressHUD];
|
|
|
+ NSLog(@"图片保存失败 %@", error);
|
|
|
+ } else {
|
|
|
+ [[TZImageManager manager] getCameraRollAlbum:NO allowPickingImage:YES completion:^(TZAlbumModel *model) {
|
|
|
+ [[TZImageManager manager] getAssetsFromFetchResult:model.result allowPickingVideo:NO allowPickingImage:YES completion:^(NSArray<TZAssetModel *> *models) {
|
|
|
+ [tzImagePickerVc hideProgressHUD];
|
|
|
+ TZAssetModel *assetModel = [models firstObject];
|
|
|
+ if (tzImagePickerVc.sortAscendingByModificationDate) {
|
|
|
+ assetModel = [models lastObject];
|
|
|
+ }
|
|
|
+ // 允许裁剪,去裁剪
|
|
|
+ TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initCropTypeWithAsset:assetModel.asset photo:image completion:^(UIImage *cropImage, id asset) {
|
|
|
+
|
|
|
+ self.imageData = UIImageJPEGRepresentation(cropImage, 0.2);
|
|
|
+ self.avatar.image = cropImage;
|
|
|
+ _imageData = UIImageJPEGRepresentation(cropImage, 0.2);
|
|
|
+ [self PushInfo];
|
|
|
+ }];
|
|
|
+ [self presentViewController:imagePicker animated:YES completion:nil];
|
|
|
+ }];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
|
|
|
+
|
|
|
+ _imageData = UIImageJPEGRepresentation(photos[0], 0.2);
|
|
|
+ self.avatar.image = photos[0];
|
|
|
+ [picker dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ [self PushInfo];
|
|
|
+}
|
|
|
+
|
|
|
+- (IBAction)changeName:(id)sender {
|
|
|
+ InfoNickNameViewController * nameVc = [[InfoNickNameViewController alloc]init];
|
|
|
+ nameVc.nameStr = nickName;
|
|
|
+ [self.navigationController pushViewController:nameVc animated:YES];
|
|
|
+}
|
|
|
+@end
|