|
|
|
|
//
|
|
|
|
|
// OfficialAccountPushSwitch.m
|
|
|
|
|
// tongxin
|
|
|
|
|
//
|
|
|
|
|
// Created by Apple on 2019/1/21.
|
|
|
|
|
// Copyright © 2019年 xTT. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "OfficialAccountPushSwitch.h"
|
|
|
|
|
#import <Photos/Photos.h>
|
|
|
|
|
#import <WXApi.h>
|
|
|
|
|
//#import "WXApiObject.h"
|
|
|
|
|
#import "WechatAuthSDK.h"
|
|
|
|
|
#import "EditMeViewController.h"
|
|
|
|
|
|
|
|
|
|
@interface OfficialAccountPushSwitch ()
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation OfficialAccountPushSwitch
|
|
|
|
|
|
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
//隐藏导航栏
|
|
|
|
|
self.navigationController.navigationBarHidden = YES;
|
|
|
|
|
|
|
|
|
|
[self loadData];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
//显示导航栏
|
|
|
|
|
self.navigationController.navigationBarHidden = NO;
|
|
|
|
|
[self StopShakeWithBtn:self.openNotificationBtn];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
获取此账号的 公众号是否关注,是否开启推送等信息
|
|
|
|
|
*/
|
|
|
|
|
-(void)loadData{
|
|
|
|
|
WEAKSELF
|
|
|
|
|
[cUser getUserInfoSuccess:^(id responseObject) {
|
|
|
|
|
if(cUser.status.intValue == 2){ //没有关注公众号
|
|
|
|
|
[weakSelf shakeToShow:self.openNotificationBtn];
|
|
|
|
|
}else{
|
|
|
|
|
[weakSelf StopShakeWithBtn:self.openNotificationBtn];
|
|
|
|
|
}
|
|
|
|
|
} failure:nil];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//MARK: 按钮动画抖动
|
|
|
|
|
-(void)shakeToShow:(UIButton *)button{
|
|
|
|
|
|
|
|
|
|
CAKeyframeAnimation* keyAnima = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
|
|
|
|
|
|
|
|
|
|
// animation.duration = 0.5;
|
|
|
|
|
// animation.repeatCount = 0;
|
|
|
|
|
//2, 告诉系统执行什么动画。
|
|
|
|
|
keyAnima.values = @[@(-M_PI_4 /90.0 * 5),@(M_PI_4 /90.0 * 5),@(-M_PI_4 /90.0 * 5)];
|
|
|
|
|
// 3, 执行完之后不删除动画
|
|
|
|
|
|
|
|
|
|
keyAnima.removedOnCompletion = NO;
|
|
|
|
|
// 4, 执行完之后保存最新的状态
|
|
|
|
|
|
|
|
|
|
keyAnima.fillMode = kCAFillModeForwards;
|
|
|
|
|
// 5, 动画执行时间
|
|
|
|
|
|
|
|
|
|
keyAnima.duration = 0.2;
|
|
|
|
|
// 6, 设置重复次数。
|
|
|
|
|
|
|
|
|
|
keyAnima.repeatCount = MAXFLOAT;
|
|
|
|
|
|
|
|
|
|
// NSMutableArray *values = [NSMutableArray array];
|
|
|
|
|
//
|
|
|
|
|
// [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
|
|
|
|
|
//
|
|
|
|
|
// [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
|
|
|
|
|
//
|
|
|
|
|
// [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
|
|
|
|
|
//
|
|
|
|
|
// [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
|
|
|
|
|
//
|
|
|
|
|
// keyAnima.values = values;
|
|
|
|
|
|
|
|
|
|
[button.layer addAnimation:keyAnima forKey:@"ButtonShake"];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//MARK: 按钮动画停止抖动
|
|
|
|
|
- (void)StopShakeWithBtn:(UIButton*)button{
|
|
|
|
|
[button.layer removeAnimationForKey:@"ButtonShake"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
WEAKSELF
|
|
|
|
|
//MARK: 灭屏后亮屏会 通知
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
|
|
|
|
|
[weakSelf loadData];
|
|
|
|
|
}];
|
|
|
|
|
//判断性别
|
|
|
|
|
NSString *sexImageName ;
|
|
|
|
|
if([cUser.cDevice.sex isEqualToString:@"girl"]){
|
|
|
|
|
//女
|
|
|
|
|
sexImageName = @"icon_girl_head_portrait_1";
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
//男
|
|
|
|
|
sexImageName = @"icon_boy_head_portrait_1";
|
|
|
|
|
}
|
|
|
|
|
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:cUser.cDevice.avator] placeholderImage:[myHelper getImageWithName:sexImageName]];
|
|
|
|
|
self.headImageView.layer.cornerRadius = self.headImageView.frame.size.width/2;
|
|
|
|
|
self.headImageView.layer.masksToBounds = YES;
|
|
|
|
|
self.nameLabel.text = cUser.cDevice.name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.openNotificationBtn.layer.cornerRadius = 4;
|
|
|
|
|
self.openNotificationBtn.backgroundColor = mainColor;
|
|
|
|
|
[self.openNotificationBtn setTitleColor:[UIColor whiteColor] forState:0];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (IBAction)leftBtn:(id)sender {
|
|
|
|
|
[self goBack:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//MARK: 跳转 开关设置页面
|
|
|
|
|
- (IBAction)setUpBtnAction:(id)sender {
|
|
|
|
|
|
|
|
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
|
|
|
|
|
UIViewController *vc =[sb instantiateViewControllerWithIdentifier:@"OffcialAccountSettingVC"];
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
打开通知
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
- (IBAction)openNotificationAction:(id)sender {
|
|
|
|
|
WEAKSELF
|
|
|
|
|
if(cUser.status.intValue == 2){
|
|
|
|
|
//未关注公众号
|
|
|
|
|
//首先判断是否是 微信登录 或者是 手机号登录绑定微信
|
|
|
|
|
if(
|
|
|
|
|
[myHelper getNowAccoutType:cUser] == 2
|
|
|
|
|
|| (cUser.account_status.intValue == 1 && cUser.wx_status.intValue == 1)
|
|
|
|
|
){
|
|
|
|
|
// 已经具备条件了
|
|
|
|
|
// 关注微信公众号,你将可以在微信收到宝贝的消息,是否前往关注?
|
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"关注微信公众号【童信汇】,你将可以在微信收到宝贝的消息,是否前往关注?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
|
|
|
|
//去截图 跳转 微信
|
|
|
|
|
[weakSelf saveImageView:self.view];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil];
|
|
|
|
|
alertView.cancelOnTouch = NO;
|
|
|
|
|
[alertView showAnimated:YES completionHandler:nil];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
// 当前账号未绑定微信,是否前往绑定?
|
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"当前账号未绑定微信,是否前往绑定?" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
|
|
|
|
|
|
|
|
|
//跳转用户资料页面 ---> 提示,绑定微信页面
|
|
|
|
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
|
|
|
|
|
EditMeViewController *vc =[sb instantiateViewControllerWithIdentifier:@"EditMeViewController"];
|
|
|
|
|
vc.willLoadBlack = ^{
|
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"请绑定微信,并关注微信公众号【童信汇】" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
|
|
|
|
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil];
|
|
|
|
|
alertView.cancelOnTouch = NO;
|
|
|
|
|
[alertView showAnimated:YES completionHandler:nil];
|
|
|
|
|
};
|
|
|
|
|
[weakSelf.navigationController pushViewController:vc animated:YES];
|
|
|
|
|
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil];
|
|
|
|
|
alertView.cancelOnTouch = NO;
|
|
|
|
|
[alertView showAnimated:YES completionHandler:nil];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
//如果是已经关注微信公众号,但已将通知关闭,点击“开启通知”按钮,将通知状态打开,并提示“开启成功
|
|
|
|
|
if(cUser.status.intValue == 1){
|
|
|
|
|
[SVProgressHUD showInfoWithStatus:@"微信通知已开启,无需重复开启"];
|
|
|
|
|
[SVProgressHUD dismissWithDelay:1];
|
|
|
|
|
}else{
|
|
|
|
|
[cUser setGZHSwitchStatus:@(1) Success:^(id responseObject) {
|
|
|
|
|
[SVProgressHUD showSuccessWithStatus:@"开启成功"];
|
|
|
|
|
[SVProgressHUD dismissWithDelay:1];
|
|
|
|
|
} failure:^(id faiObject) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//截屏分享 传入想截屏的view(也可以是controller webview只能截当前屏幕-_-`,用其他的方法)
|
|
|
|
|
-(void)saveImageView:(UIView*)view{
|
|
|
|
|
|
|
|
|
|
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0);
|
|
|
|
|
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
|
|
|
|
[view.layer renderInContext:ctx];
|
|
|
|
|
// 这个是要分享图片的样式(自定义的)
|
|
|
|
|
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
|
|
//保存到本地相机
|
|
|
|
|
UIImageWriteToSavedPhotosAlbum(newImage,self,@selector(image:didFinishSavingWithError:contextInfo:),nil);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
|
|
|
|
|
if(error){
|
|
|
|
|
xLog(@"error: %@",error.description);
|
|
|
|
|
if(PHPhotoLibrary.authorizationStatus != PHAuthorizationStatusAuthorized){
|
|
|
|
|
//可能是没有权限
|
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"请为%@打开相机权限",APPName] style:LGAlertViewStyleAlert buttonTitles:@[@"前往设置"] cancelButtonTitle:@"取消" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
|
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil];
|
|
|
|
|
alertView.cancelOnTouch = NO;
|
|
|
|
|
[alertView showAnimated:YES completionHandler:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
xLog(@"截屏保存成功");
|
|
|
|
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"截图保存至相册成功,微信使用\"扫一扫\",右上角相册选择截图,扫描截图并关注公众号即可开启通知" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:@"" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
|
|
|
|
|
|
|
|
|
|
[self openScheme:@"weixin://"];
|
|
|
|
|
|
|
|
|
|
} cancelHandler:nil destructiveHandler:nil];
|
|
|
|
|
alertView.cancelOnTouch = NO;
|
|
|
|
|
[alertView showAnimated:YES completionHandler:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)openScheme:(NSString *)scheme {
|
|
|
|
|
UIApplication *application = [UIApplication sharedApplication];
|
|
|
|
|
NSURL *URL = [NSURL URLWithString:scheme];
|
|
|
|
|
|
|
|
|
|
//iOS 10 以后
|
|
|
|
|
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
|
|
|
|
|
//1 如果这个要打开的URL有效,并且在应用中配置它布尔值为true(YES)时才可以打开,否则打不开
|
|
|
|
|
// NSDictionary *options = @{UIApplicationOpenURLOptionUniversalLinksOnly : @YES};
|
|
|
|
|
//2 此时与openURL功能相似
|
|
|
|
|
NSDictionary *options =@{};
|
|
|
|
|
[application openURL:URL options:options
|
|
|
|
|
completionHandler:^(BOOL success) {
|
|
|
|
|
NSLog(@"Open %@: %d",scheme,success);
|
|
|
|
|
}];
|
|
|
|
|
} else {
|
|
|
|
|
if ([application canOpenURL:URL]) {
|
|
|
|
|
BOOL success = [application openURL:URL];
|
|
|
|
|
NSLog(@"Open %@: %d",scheme,success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)dealloc{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; //移除亮灭屏通知
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
#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
|