add
This commit is contained in:
+4
-3
@@ -27,8 +27,8 @@
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
// Override point for customization after application launch.
|
||||
//[NSThread sleepForTimeInterval:1];//延迟启动
|
||||
|
||||
_isMasking = NO;
|
||||
self.isMasking = [GiGaUserDefault isMasking];
|
||||
//_isMasking = NO;
|
||||
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
|
||||
[self registLocalNotification];
|
||||
[self configThridPartyWithOptions:launchOptions];
|
||||
@@ -138,7 +138,7 @@
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
|
||||
[GiGaUserDefault saveisMaskingflag:_isMasking];
|
||||
//app 挂起 面膜时间未结束 发送本地通知提醒
|
||||
if (_isMasking) {
|
||||
|
||||
@@ -147,6 +147,7 @@
|
||||
// [[GiGaLocalNotificationManager localNotifiationCenter] cancelAllLocalNoitification];
|
||||
}
|
||||
[[GiGaLocalNotificationManager localNotifiationCenter] cancelAllLocalNoitification];
|
||||
|
||||
}
|
||||
|
||||
-(void)remoteControlReceivedWithEvent:(UIEvent *)event
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// GIGaDateHelper.h
|
||||
// MasKTimeCountTime
|
||||
//
|
||||
// Created by lianxiang on 2018/10/19.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface GIGaDateHelper : NSObject
|
||||
|
||||
+(NSString *)getNowTimeTimestamp2;
|
||||
+(NSDate *)getStartDate;
|
||||
+(void)saveSatrtDate;
|
||||
+(int)getTimebySubtracting:(NSDate*)Date1 andDate2:(NSDate*)Date2;
|
||||
+(void)saveisMaskingflag:(BOOL)masking;
|
||||
+(BOOL)isMasking;
|
||||
+(void)removeStartDate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// GIGaDateHelper.m
|
||||
// MasKTimeCountTime
|
||||
//
|
||||
// Created by lianxiang on 2018/10/19.
|
||||
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
||||
//
|
||||
|
||||
#import "GIGaDateHelper.h"
|
||||
|
||||
@implementation GIGaDateHelper
|
||||
|
||||
//获取当前时间 单位秒
|
||||
+(NSString *)getNowTimeTimestamp2{
|
||||
|
||||
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
|
||||
NSLog(@"date :%@",dat);
|
||||
|
||||
NSTimeInterval a=[dat timeIntervalSince1970];
|
||||
NSString*timeString = [NSString stringWithFormat:@"%0.f", a];
|
||||
//转为字符型 ;
|
||||
return timeString;
|
||||
|
||||
}
|
||||
|
||||
+(NSDate *)getStartDate{
|
||||
|
||||
NSDate *start = [[NSUserDefaults standardUserDefaults] objectForKey:@"start"];
|
||||
|
||||
return start;
|
||||
|
||||
}
|
||||
|
||||
+(void )saveSatrtDate{
|
||||
|
||||
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
|
||||
[[NSUserDefaults standardUserDefaults] setObject:dat forKey:@"start"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
}
|
||||
|
||||
+(void)removeStartDate{
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"start"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
}
|
||||
|
||||
+(int)getTimebySubtracting:(NSDate*)Date1 andDate2:(NSDate*)Date2
|
||||
{
|
||||
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
|
||||
unsigned int unitFlags = NSCalendarUnitSecond;
|
||||
|
||||
NSDateComponents *comps = [gregorian components: unitFlags fromDate:Date1 toDate:Date2 options:0];
|
||||
|
||||
int seconds = (int)[comps second];
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
+(void)saveisMaskingflag:(BOOL)masking{
|
||||
[[NSUserDefaults standardUserDefaults] setBool:masking forKey:@"isMasking"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
+(BOOL)isMasking{
|
||||
|
||||
BOOL ismasking = [[NSUserDefaults standardUserDefaults] boolForKey:@"isMasking"];
|
||||
return ismasking;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -75,4 +75,8 @@
|
||||
+(void)saveUserTestFlag:(BOOL)tested;
|
||||
+(BOOL)isUserTest;
|
||||
|
||||
|
||||
+(void)saveisMaskingflag:(BOOL)masking;
|
||||
+(BOOL)isMasking;
|
||||
|
||||
@end
|
||||
|
||||
@@ -166,4 +166,16 @@ NSString *const kShowUserTested = @"kShowUserTested";
|
||||
return showedGaurd;
|
||||
}
|
||||
|
||||
+(void)saveisMaskingflag:(BOOL)masking{
|
||||
[[NSUserDefaults standardUserDefaults] setBool:masking forKey:@"isMasking"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
}
|
||||
|
||||
+(BOOL)isMasking{
|
||||
|
||||
BOOL ismasking = [[NSUserDefaults standardUserDefaults] boolForKey:@"isMasking"];
|
||||
return ismasking;
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* finishTimeStamp 结束的时间戳
|
||||
*/
|
||||
-(void)countDownWithStratTimeStamp:(long)starTimeStamp finishTimeStamp:(long)finishTimeStamp completeBlock:(void (^)(NSInteger day,NSInteger hour,NSInteger minute,NSInteger second))completeBlock;
|
||||
|
||||
-(void)countDownWithtimerInterval:(NSTimeInterval)timerInterval completeBlock:(void (^)(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second))completeBlock;
|
||||
|
||||
/**
|
||||
* 每秒走一次,回调block
|
||||
|
||||
@@ -54,6 +54,42 @@
|
||||
}
|
||||
}
|
||||
|
||||
-(void)countDownWithtimerInterval:(NSTimeInterval)timerInterval completeBlock:(void (^)(NSInteger, NSInteger, NSInteger, NSInteger))completeBlock{
|
||||
|
||||
if (_timer == nil) {
|
||||
|
||||
__block int timeout = timerInterval;
|
||||
if (timeout !=0) {
|
||||
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
||||
dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0*NSEC_PER_SEC, 0);//每秒执行
|
||||
dispatch_source_set_event_handler(_timer, ^{
|
||||
if (timeout<=0) {
|
||||
//记时结束, 关闭
|
||||
dispatch_source_cancel(self->_timer);
|
||||
self->_timer = nil;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completeBlock(0,0,0,0);
|
||||
});
|
||||
}else{
|
||||
int days = (int)(timeout/(3600*24));
|
||||
int hours = (int)((timeout-days*24*3600)/3600);
|
||||
int minute = (int)(timeout-days*24*3600-hours*3600)/60;
|
||||
int second = timeout-days*24*3600-hours*3600-minute*60;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completeBlock(days,hours,minute,second);
|
||||
});
|
||||
timeout--;
|
||||
}
|
||||
});
|
||||
dispatch_resume(_timer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void)countDownWithPER_SECBlock:(void (^)(void))PER_SECBlock{
|
||||
if (_timer==nil) {
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
case 0://测试环境
|
||||
{
|
||||
|
||||
// [[NSUserDefaults standardUserDefaults] setValue:@"http://apiyts.s1.natapp.cc/v1/" forKey:@"MainUrl"];
|
||||
// [[NSUserDefaults standardUserDefaults] setValue:@"http://wsyts.s1.natapp.cc" forKey:@"gigasocketUrl"];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"https://api.mianmoshijian.com/v1/" forKey:@"MainUrl"];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"https://ws.mianmoshijian.com" forKey:@"gigasocketUrl"];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"http://apiyts.s1.natapp.cc/v1/" forKey:@"MainUrl"];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:@"http://wsyts.s1.natapp.cc" forKey:@"gigasocketUrl"];
|
||||
// [[NSUserDefaults standardUserDefaults] setValue:@"https://api.mianmoshijian.com/v1/" forKey:@"MainUrl"];
|
||||
// [[NSUserDefaults standardUserDefaults] setValue:@"https://ws.mianmoshijian.com" forKey:@"gigasocketUrl"];
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -54,7 +54,6 @@
|
||||
<string>是否允许此App使用您的相册?</string>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>audio</string>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
|
||||
@@ -36,10 +36,11 @@
|
||||
#import "MaskHistryRecord.h"
|
||||
#import "MaskTimeTopAnimationView.h"
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import "GIGaDateHelper.h"
|
||||
|
||||
@interface GiGaMaskTaskViewController ()<MaskCirCularProGressViewDelegate,MaskTimeTextViewDelegate>
|
||||
{
|
||||
AVAudioPlayer *_musicPalyer;
|
||||
|
||||
AVAudioPlayer *_startMaskMusic;
|
||||
|
||||
}
|
||||
@@ -258,8 +259,25 @@
|
||||
[self setUpNav];
|
||||
[self initUI];
|
||||
[self addNotify];
|
||||
[self creatBackGroundMusic];
|
||||
//[self creatBackGroundMusic];
|
||||
[self creatMaskTimeSatrtMusic];
|
||||
//判断是否有倒数计时
|
||||
[self digIsMasking];
|
||||
|
||||
}
|
||||
|
||||
-(void)digIsMasking{
|
||||
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
|
||||
NSString *st = nil;
|
||||
if (delegate.isMasking) {
|
||||
NSLog(@"倒计时中");
|
||||
st = @"YES";
|
||||
[self animaMask];
|
||||
|
||||
}else{
|
||||
st = @"NO";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -288,6 +306,8 @@
|
||||
[self.cicleProgressView stop];
|
||||
//手动结束时结束peding通知
|
||||
[[GiGaLocalNotificationManager localNotifiationCenter] cancelAllLocalNoitification];
|
||||
[GIGaDateHelper removeStartDate];
|
||||
[GIGaDateHelper saveisMaskingflag:NO];
|
||||
[self maskTimeEnd];
|
||||
}
|
||||
}];
|
||||
@@ -473,7 +493,7 @@
|
||||
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicUrl error:&payerError];
|
||||
player.numberOfLoops = -1;//-1 无限
|
||||
player.volume = 0;
|
||||
_musicPalyer = player;
|
||||
//_musicPalyer = player;
|
||||
[[AVAudioSession sharedInstance] setActive:YES error:nil];
|
||||
//设置后台模式和锁屏模式下依然能够播放
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
|
||||
@@ -502,18 +522,14 @@
|
||||
[self sendBengainMaskTime];
|
||||
[self createInputView]; //出现弹幕
|
||||
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
|
||||
if (delegate.isMasking) {
|
||||
return;
|
||||
}
|
||||
NSTimeInterval timeInterVal = [GiGaUserDefault getUserMaskeTime];
|
||||
[self.cicleProgressView startWith:timeInterVal];
|
||||
|
||||
delegate.isMasking = YES;
|
||||
[_startMaskMusic play];
|
||||
[_musicPalyer play];
|
||||
//[_musicPalyer play];
|
||||
// [self setBackGroundPlayingInfo];//锁屏音频信息
|
||||
|
||||
//总时间隔 s
|
||||
NSTimeInterval timeInterVal = [GiGaUserDefault getUserMaskeTime];
|
||||
|
||||
[self.cicleProgressView startWith:timeInterVal];
|
||||
|
||||
//底部弹窗
|
||||
//[self showWaringView];
|
||||
|
||||
@@ -563,13 +579,15 @@
|
||||
|
||||
#pragma mark 面膜时间结束
|
||||
-(void)maskTimeEnd{
|
||||
|
||||
self.openDanmuButton.hidden = YES;
|
||||
[self sendEndMaskTime];
|
||||
NC_POST_NAME_OBJECT(kUserNoti_MASKEND, nil);
|
||||
//面膜时间结束时设置 全局变量 不再发送本地通知 提醒
|
||||
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
|
||||
delegate.isMasking = NO;
|
||||
[_musicPalyer stop];
|
||||
|
||||
//[_musicPalyer stop];
|
||||
|
||||
//震动 需用户手动开启震动模式
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
@@ -792,6 +810,7 @@
|
||||
[UIView animateWithDuration:0.4 animations:^{
|
||||
self.waringView.frame = CGRectMake(0,CGRectGetMaxY(self.view.frame) - 44 - PhoneX_BottomMargin, self.view.frame.size.width, 44);
|
||||
}];
|
||||
|
||||
[self.waringView showView];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#import "MaskTimeCircularProgressView.h"
|
||||
#import "LXCountTimer.h"
|
||||
#import "SHineLabel.h"
|
||||
#import "GIGaDateHelper.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface MaskTimeCircularProgressView()
|
||||
@property (nonatomic) CADisplayLink *displayLink;
|
||||
@@ -20,7 +22,6 @@
|
||||
@property (nonatomic,strong) NSTimer *playTimer;
|
||||
@property (nonatomic,strong) UIImageView *holderImageView;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation MaskTimeCircularProgressView
|
||||
@@ -145,8 +146,8 @@
|
||||
slice.lineCap = kCALineJoinRound;
|
||||
slice.lineJoin = kCALineJoinBevel;
|
||||
slice.path = smoothedPath.CGPath;
|
||||
|
||||
return slice;
|
||||
|
||||
}
|
||||
|
||||
- (void)setProgress:(float)progress{
|
||||
@@ -180,7 +181,10 @@
|
||||
- (void)startWith:(NSTimeInterval)time{
|
||||
|
||||
self.timeinterval = time;
|
||||
|
||||
[self countDown:time];
|
||||
|
||||
//进度圆环
|
||||
[self start];
|
||||
}
|
||||
|
||||
@@ -200,13 +204,37 @@
|
||||
|
||||
-(void)countDown:(NSTimeInterval)timeInterVal{
|
||||
|
||||
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
|
||||
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
|
||||
NSString *hour = timesArr[0];
|
||||
NSString *min = timesArr[1];
|
||||
NSString *sec = timesArr[2];
|
||||
[self countTimeBegain:hour.integerValue minute:min.integerValue second:sec.integerValue];
|
||||
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
|
||||
|
||||
if (delegate.isMasking) {
|
||||
|
||||
}else{
|
||||
|
||||
[GIGaDateHelper saveSatrtDate];
|
||||
}
|
||||
|
||||
NSDate *startDate = [GIGaDateHelper getStartDate];
|
||||
NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
|
||||
if (startDate == nil) {
|
||||
startDate = dat;
|
||||
}
|
||||
|
||||
NSTimeInterval passt = [GIGaDateHelper getTimebySubtracting:startDate andDate2:dat];
|
||||
NSLog(@"passT %0.f",passt);
|
||||
|
||||
NSTimeInterval cunrenShowTimCount = timeInterVal > passt ? timeInterVal - passt: timeInterVal;
|
||||
delegate.isMasking= YES;
|
||||
weakify(self);
|
||||
[self.timer countDownWithtimerInterval:cunrenShowTimCount completeBlock:^(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second) {
|
||||
[weakSelf refreshTimeCount:hour minute:minute second:second];
|
||||
if (minute==0 && second == 0) {
|
||||
delegate.isMasking = NO;
|
||||
[GIGaDateHelper removeStartDate];
|
||||
[GIGaDateHelper saveisMaskingflag:NO];
|
||||
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
#pragma mark 开始计时
|
||||
@@ -218,8 +246,11 @@
|
||||
[self.timer countDownWithStratTimeStamp:nowTimestamp finishTimeStamp:futrueTimestamp completeBlock:^(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second) {
|
||||
[weakSelf refreshTimeCount:hour minute:minute second:second];
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)refreshTimeCount:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
|
||||
|
||||
self.countLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minute,second];
|
||||
|
||||
Reference in New Issue
Block a user