ad localnoti background music

This commit is contained in:
lianxiang
2018-08-24 21:20:18 +08:00
parent d43d7eaaf6
commit 983bb33644
25 changed files with 1773 additions and 35 deletions
+64
View File
@@ -71,6 +71,12 @@
83835BCA212E8045001480F2 /* GIGAQuetionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83835BC9212E8045001480F2 /* GIGAQuetionView.m */; }; 83835BCA212E8045001480F2 /* GIGAQuetionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83835BC9212E8045001480F2 /* GIGAQuetionView.m */; };
83835BCD212E856A001480F2 /* NSString+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 83835BCC212E856A001480F2 /* NSString+MD5.m */; }; 83835BCD212E856A001480F2 /* NSString+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 83835BCC212E856A001480F2 /* NSString+MD5.m */; };
83835BD0212E8B9C001480F2 /* GiGaQuestionModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */; }; 83835BD0212E8B9C001480F2 /* GiGaQuestionModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */; };
838388C4212F934400D14C53 /* pomodoSound.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 838388C3212F934400D14C53 /* pomodoSound.m4a */; };
838388C8212F9C4200D14C53 /* GiGaLocalNotificationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 838388C7212F9C4200D14C53 /* GiGaLocalNotificationManager.m */; };
838388CA212FA00200D14C53 /* MaskTime.png in Resources */ = {isa = PBXBuildFile; fileRef = 838388C9212FA00200D14C53 /* MaskTime.png */; };
838388D3212FB7D700D14C53 /* JXTAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = 838388CE212FB7D700D14C53 /* JXTAlertController.m */; };
838388D4212FB7D700D14C53 /* JXTAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = 838388D2212FB7D700D14C53 /* JXTAlertView.m */; };
838388DA2130046D00D14C53 /* emojizone.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 838388D92130046D00D14C53 /* emojizone.mp4 */; };
83A2270C212A97ED00B3E75C /* MaskViewBootomWaringView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A2270B212A97ED00B3E75C /* MaskViewBootomWaringView.m */; }; 83A2270C212A97ED00B3E75C /* MaskViewBootomWaringView.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A2270B212A97ED00B3E75C /* MaskViewBootomWaringView.m */; };
83A22712212A9EA900B3E75C /* UIView+Sizes.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22710212A9EA900B3E75C /* UIView+Sizes.m */; }; 83A22712212A9EA900B3E75C /* UIView+Sizes.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22710212A9EA900B3E75C /* UIView+Sizes.m */; };
83A22718212ABDFF00B3E75C /* GiGaBlockButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22717212ABDFF00B3E75C /* GiGaBlockButton.m */; }; 83A22718212ABDFF00B3E75C /* GiGaBlockButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A22717212ABDFF00B3E75C /* GiGaBlockButton.m */; };
@@ -209,6 +215,16 @@
83835BCC212E856A001480F2 /* NSString+MD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+MD5.m"; sourceTree = "<group>"; }; 83835BCC212E856A001480F2 /* NSString+MD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+MD5.m"; sourceTree = "<group>"; };
83835BCE212E8B9C001480F2 /* GiGaQuestionModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiGaQuestionModel.h; sourceTree = "<group>"; }; 83835BCE212E8B9C001480F2 /* GiGaQuestionModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiGaQuestionModel.h; sourceTree = "<group>"; };
83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiGaQuestionModel.m; sourceTree = "<group>"; }; 83835BCF212E8B9C001480F2 /* GiGaQuestionModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiGaQuestionModel.m; sourceTree = "<group>"; };
838388C3212F934400D14C53 /* pomodoSound.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = pomodoSound.m4a; sourceTree = "<group>"; };
838388C6212F9C4200D14C53 /* GiGaLocalNotificationManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiGaLocalNotificationManager.h; sourceTree = "<group>"; };
838388C7212F9C4200D14C53 /* GiGaLocalNotificationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiGaLocalNotificationManager.m; sourceTree = "<group>"; };
838388C9212FA00200D14C53 /* MaskTime.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MaskTime.png; sourceTree = "<group>"; };
838388CD212FB7D700D14C53 /* JXTAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertController.h; sourceTree = "<group>"; };
838388CE212FB7D700D14C53 /* JXTAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JXTAlertController.m; sourceTree = "<group>"; };
838388CF212FB7D700D14C53 /* JXTAlertManagerHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertManagerHeader.h; sourceTree = "<group>"; };
838388D1212FB7D700D14C53 /* JXTAlertView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JXTAlertView.h; sourceTree = "<group>"; };
838388D2212FB7D700D14C53 /* JXTAlertView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JXTAlertView.m; sourceTree = "<group>"; };
838388D92130046D00D14C53 /* emojizone.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = emojizone.mp4; sourceTree = "<group>"; };
83A2270A212A97ED00B3E75C /* MaskViewBootomWaringView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MaskViewBootomWaringView.h; sourceTree = "<group>"; }; 83A2270A212A97ED00B3E75C /* MaskViewBootomWaringView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MaskViewBootomWaringView.h; sourceTree = "<group>"; };
83A2270B212A97ED00B3E75C /* MaskViewBootomWaringView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MaskViewBootomWaringView.m; sourceTree = "<group>"; }; 83A2270B212A97ED00B3E75C /* MaskViewBootomWaringView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MaskViewBootomWaringView.m; sourceTree = "<group>"; };
83A22710212A9EA900B3E75C /* UIView+Sizes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Sizes.m"; sourceTree = "<group>"; }; 83A22710212A9EA900B3E75C /* UIView+Sizes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Sizes.m"; sourceTree = "<group>"; };
@@ -277,6 +293,9 @@
83346AC8212BD4160054D597 /* Source */ = { 83346AC8212BD4160054D597 /* Source */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
838388D92130046D00D14C53 /* emojizone.mp4 */,
838388C9212FA00200D14C53 /* MaskTime.png */,
838388C3212F934400D14C53 /* pomodoSound.m4a */,
83346AD0212BF5B70054D597 /* useragreement.html */, 83346AD0212BF5B70054D597 /* useragreement.html */,
); );
path = Source; path = Source;
@@ -440,6 +459,8 @@
8361B3FC21215C7400238FEB /* Common */ = { 8361B3FC21215C7400238FEB /* Common */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
838388CB212FB7D700D14C53 /* JXTAlertManager */,
838388C5212F9C0A00D14C53 /* GiGaLocalNotificationManager */,
83835BC4212E7B96001480F2 /* GiGaNavTitileView */, 83835BC4212E7B96001480F2 /* GiGaNavTitileView */,
835060AA212D4C0F007E6220 /* GiGaFileManager */, 835060AA212D4C0F007E6220 /* GiGaFileManager */,
83346AC8212BD4160054D597 /* Source */, 83346AC8212BD4160054D597 /* Source */,
@@ -674,6 +695,43 @@
path = GiGaNavTitileView; path = GiGaNavTitileView;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
838388C5212F9C0A00D14C53 /* GiGaLocalNotificationManager */ = {
isa = PBXGroup;
children = (
838388C6212F9C4200D14C53 /* GiGaLocalNotificationManager.h */,
838388C7212F9C4200D14C53 /* GiGaLocalNotificationManager.m */,
);
path = GiGaLocalNotificationManager;
sourceTree = "<group>";
};
838388CB212FB7D700D14C53 /* JXTAlertManager */ = {
isa = PBXGroup;
children = (
838388CC212FB7D700D14C53 /* AlertController */,
838388CF212FB7D700D14C53 /* JXTAlertManagerHeader.h */,
838388D0212FB7D700D14C53 /* AlertView */,
);
path = JXTAlertManager;
sourceTree = "<group>";
};
838388CC212FB7D700D14C53 /* AlertController */ = {
isa = PBXGroup;
children = (
838388CD212FB7D700D14C53 /* JXTAlertController.h */,
838388CE212FB7D700D14C53 /* JXTAlertController.m */,
);
path = AlertController;
sourceTree = "<group>";
};
838388D0212FB7D700D14C53 /* AlertView */ = {
isa = PBXGroup;
children = (
838388D1212FB7D700D14C53 /* JXTAlertView.h */,
838388D2212FB7D700D14C53 /* JXTAlertView.m */,
);
path = AlertView;
sourceTree = "<group>";
};
83A22719212AC7FC00B3E75C /* View */ = { 83A22719212AC7FC00B3E75C /* View */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@@ -861,9 +919,12 @@
files = ( files = (
83346AC6212BBC8C0054D597 /* GiGaRegistViewController.xib in Resources */, 83346AC6212BBC8C0054D597 /* GiGaRegistViewController.xib in Resources */,
8361B3D6212155C300238FEB /* LaunchScreen.storyboard in Resources */, 8361B3D6212155C300238FEB /* LaunchScreen.storyboard in Resources */,
838388DA2130046D00D14C53 /* emojizone.mp4 in Resources */,
83A22720212AC8C100B3E75C /* GiGaUserLoginVC.xib in Resources */, 83A22720212AC8C100B3E75C /* GiGaUserLoginVC.xib in Resources */,
838388C4212F934400D14C53 /* pomodoSound.m4a in Resources */,
83346AC1212BB50A0054D597 /* PassWordResetVC.xib in Resources */, 83346AC1212BB50A0054D597 /* PassWordResetVC.xib in Resources */,
83346AD1212BF5B70054D597 /* useragreement.html in Resources */, 83346AD1212BF5B70054D597 /* useragreement.html in Resources */,
838388CA212FA00200D14C53 /* MaskTime.png in Resources */,
83835BA8212E4748001480F2 /* MAssaageCenterCell.xib in Resources */, 83835BA8212E4748001480F2 /* MAssaageCenterCell.xib in Resources */,
8361B3D3212155C300238FEB /* Assets.xcassets in Resources */, 8361B3D3212155C300238FEB /* Assets.xcassets in Resources */,
8361B3D1212155C200238FEB /* Main.storyboard in Resources */, 8361B3D1212155C200238FEB /* Main.storyboard in Resources */,
@@ -978,7 +1039,9 @@
8361B40721215E6F00238FEB /* GiGaHelper.m in Sources */, 8361B40721215E6F00238FEB /* GiGaHelper.m in Sources */,
83835BA0212E43BD001480F2 /* GiGaMasssagesVC.m in Sources */, 83835BA0212E43BD001480F2 /* GiGaMasssagesVC.m in Sources */,
8357ADCD2123C091000816F2 /* GiGaNetManager.m in Sources */, 8357ADCD2123C091000816F2 /* GiGaNetManager.m in Sources */,
838388D4212FB7D700D14C53 /* JXTAlertView.m in Sources */,
835060A9212D38EE007E6220 /* GiGaStartAdView.m in Sources */, 835060A9212D38EE007E6220 /* GiGaStartAdView.m in Sources */,
838388D3212FB7D700D14C53 /* JXTAlertController.m in Sources */,
833DA7762122A62000A5C614 /* GiGaMaskTaskViewController.m in Sources */, 833DA7762122A62000A5C614 /* GiGaMaskTaskViewController.m in Sources */,
8357ADD02123C5F7000816F2 /* GiGaAPIRequest.m in Sources */, 8357ADD02123C5F7000816F2 /* GiGaAPIRequest.m in Sources */,
83835BD0212E8B9C001480F2 /* GiGaQuestionModel.m in Sources */, 83835BD0212E8B9C001480F2 /* GiGaQuestionModel.m in Sources */,
@@ -986,6 +1049,7 @@
8361B3D9212155C300238FEB /* main.m in Sources */, 8361B3D9212155C300238FEB /* main.m in Sources */,
835060A2212D1225007E6220 /* GiGaMeViewController.m in Sources */, 835060A2212D1225007E6220 /* GiGaMeViewController.m in Sources */,
8361B3CB212155C200238FEB /* AppDelegate.m in Sources */, 8361B3CB212155C200238FEB /* AppDelegate.m in Sources */,
838388C8212F9C4200D14C53 /* GiGaLocalNotificationManager.m in Sources */,
83835BBC212E60E5001480F2 /* MessageDetailViewController.m in Sources */, 83835BBC212E60E5001480F2 /* MessageDetailViewController.m in Sources */,
83835BCD212E856A001480F2 /* NSString+MD5.m in Sources */, 83835BCD212E856A001480F2 /* NSString+MD5.m in Sources */,
83835BC7212E7BBF001480F2 /* GiGaNavTitileView.m in Sources */, 83835BC7212E7BBF001480F2 /* GiGaNavTitileView.m in Sources */,
+20 -2
View File
@@ -7,16 +7,34 @@
// //
#import "AppDelegate.h" #import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate (GiGaConfig)<UNUserNotificationCenterDelegate>
@interface AppDelegate (GiGaConfig)
/**
v1.0 后使用
*/
- (void)setupTabBarController; - (void)setupTabBarController;
/**
服务器环境
*/
- (void)configEnvironment; - (void)configEnvironment;
//v1.0 /**
设置根视图 v1.0
*/
- (void)setupRootVC; - (void)setupRootVC;
/** /**
设置启动广告 设置启动广告
*/ */
-(void)creatAdView; -(void)creatAdView;
/**
注册本地通知
*/
-(void)registLocalNotification;
@end @end
+35 -2
View File
@@ -11,6 +11,8 @@
#import "GiGaMaskTaskViewController.h" #import "GiGaMaskTaskViewController.h"
#import "GiGaUserDefault.h" #import "GiGaUserDefault.h"
#import "GiGaStartAdView.h" #import "GiGaStartAdView.h"
#import <UserNotifications/UserNotifications.h>
#import "GiGaLocalNotificationManager.h"
@implementation AppDelegate (GiGaConfig) @implementation AppDelegate (GiGaConfig)
@@ -77,7 +79,7 @@
} }
//
- (void)setupRootVC{ - (void)setupRootVC{
GiGaMaskTaskViewController *maskeVC = [[GiGaMaskTaskViewController alloc] init]; GiGaMaskTaskViewController *maskeVC = [[GiGaMaskTaskViewController alloc] init];
@@ -89,11 +91,42 @@
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
} }
-(void)creatAdView{ -(void)creatAdView{
GiGaStartAdView *startadview = [[GiGaStartAdView alloc] initWithFrame:self.window.bounds]; GiGaStartAdView *startadview = [[GiGaStartAdView alloc] initWithFrame:self.window.bounds];
[startadview show]; [startadview show];
} }
-(void)registLocalNotification{
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
} else {
// Fallback on earlier versions
UIUserNotificationSettings *setings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
//授权
[[UIApplication sharedApplication] registerUserNotificationSettings:setings];
}
}
//接收本地通知 ios 8
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0 && [[[UIDevice currentDevice] systemVersion] floatValue] <10.0) {
[[GiGaLocalNotificationManager localNotifiationCenter] didResaveloaclNitification:notification];
}
}
@end @end
+5
View File
@@ -18,6 +18,11 @@
@interface AppDelegate (ThirdParty)<JPUSHRegisterDelegate,WXApiDelegate> @interface AppDelegate (ThirdParty)<JPUSHRegisterDelegate,WXApiDelegate>
/**
第三方SDK 配置
@param launchOptions launchOptions description
*/
-(void)configThridPartyWithOptions:(NSDictionary *)launchOptions; -(void)configThridPartyWithOptions:(NSDictionary *)launchOptions;
@end @end
+12 -1
View File
@@ -15,6 +15,9 @@
//极光推送 //极光推送
//APNS Regist //APNS Regist
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService resetBadge];
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound; entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
@@ -32,6 +35,7 @@
apsForProduction:GIGA_PUSH_ENVIRONMENT apsForProduction:GIGA_PUSH_ENVIRONMENT
advertisingIdentifier:nil]; advertisingIdentifier:nil];
//微信 //微信
@@ -61,6 +65,9 @@
// ios 10 Support // ios 10 Support
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){ - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService resetBadge];
// Required // Required
NSDictionary * userInfo = response.notification.request.content.userInfo; NSDictionary * userInfo = response.notification.request.content.userInfo;
GILog(@"ios(10.0)-userInfo%@",userInfo); GILog(@"ios(10.0)-userInfo%@",userInfo);
@@ -79,7 +86,6 @@
[JPUSHService handleRemoteNotification:userInfo]; [JPUSHService handleRemoteNotification:userInfo];
} }
completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置 completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge); // 需要执行这个方法,选择是否提醒用户,有Badge、Sound、Alert三种类型可以选择设置
} }
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
@@ -94,6 +100,9 @@
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService resetBadge];
// Required, iOS 7 Support // Required, iOS 7 Support
GILog(@"iOS 7 userInfo%@",userInfo); GILog(@"iOS 7 userInfo%@",userInfo);
[JPUSHService handleRemoteNotification:userInfo]; [JPUSHService handleRemoteNotification:userInfo];
@@ -102,6 +111,8 @@
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService resetBadge];
// Required,For systems with less than or equal to iOS6 // Required,For systems with less than or equal to iOS6
[JPUSHService handleRemoteNotification:userInfo]; [JPUSHService handleRemoteNotification:userInfo];
+1 -1
View File
@@ -12,7 +12,7 @@
@property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) UIWindow *window;
@property (nonatomic ,strong) UITabBarController *rootTabBarVC; @property (nonatomic ,strong) UITabBarController *rootTabBarVC;
@property (nonatomic) BOOL isMasking;//是否在正在面膜倒计时
@end @end
+32 -7
View File
@@ -11,6 +11,7 @@
#import "AppDelegate+ThirdParty.h" #import "AppDelegate+ThirdParty.h"
#import "GiGaUserDefault.h" #import "GiGaUserDefault.h"
#import "JPUSHService.h" #import "JPUSHService.h"
#import "GiGaLocalNotificationManager.h"
@interface AppDelegate () @interface AppDelegate ()
//保持后台长时间运行 //保持后台长时间运行
@@ -26,10 +27,15 @@
// Override point for customization after application launch. // Override point for customization after application launch.
//[NSThread sleepForTimeInterval:1];//延迟启动 //[NSThread sleepForTimeInterval:1];//延迟启动
application.applicationIconBadgeNumber = 0; _isMasking = NO;
[JPUSHService resetBadge];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self registLocalNotification];
[self configThridPartyWithOptions:launchOptions]; [self configThridPartyWithOptions:launchOptions];
[self configEnvironment]; [self configEnvironment];
[self setupRootVC]; [self setupRootVC];
//广告页 //广告页
[self creatAdView]; [self creatAdView];
@@ -41,16 +47,21 @@
- (void)applicationWillResignActive:(UIApplication *)application { - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
} }
- (void)applicationDidEnterBackground:(UIApplication *)application { - (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
//后台模式
[self creatBackGoundTask];
// 当 开启面膜时间 长期保持后台模式
if (_isMasking) {
[self creatBackGoundTask];
}
//[self creatBackGoundTask];
} }
@@ -83,18 +94,32 @@
- (void)applicationWillEnterForeground:(UIApplication *)application { - (void)applicationWillEnterForeground:(UIApplication *)application {
application.applicationIconBadgeNumber = 0; application.applicationIconBadgeNumber = 0;
[JPUSHService resetBadge]; [JPUSHService resetBadge];
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
} }
- (void)applicationDidBecomeActive:(UIApplication *)application { - (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} }
- (void)applicationWillTerminate:(UIApplication *)application { - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
//app 挂起 面膜时间未结束 将发送本地通知提醒
if (_isMasking) {
[[GiGaLocalNotificationManager localNotifiationCenter] sendLocalNotification:@"闹钟提醒!" fireTimeInterval:2 alertAction:@"面膜时间已添加闹钟提醒!" withIdentifier:kLOCALNotifiID_APPTERMINAL];
}
} }
-(void)remoteControlReceivedWithEvent:(UIEvent *)event
{
if (event.type == UIEventTypeRemoteControl ) {
}
}
@end @end
+5
View File
@@ -33,6 +33,11 @@
*/ */
+(long)getFutureTimetstamp:(NSUInteger)hour minute:(NSUInteger)min second:(NSUInteger)second; +(long)getFutureTimetstamp:(NSUInteger)hour minute:(NSUInteger)min second:(NSUInteger)second;
/**
* 系统当前时间时间戳
*/
+(long)getNowDateTimestamp;
/** /**
* NSTimeInterval 转分钟秒 * NSTimeInterval 转分钟秒
*/ */
+17 -1
View File
@@ -60,11 +60,27 @@
} }
+(long)getNowDateTimestamp{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
// ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
[formatter setDateFormat:@"YYYY年MM月dd日HH:mm:ss"];
//现在时间,你可以输出来看下是什么格式
NSDate *datenow = [NSDate date];
//----------将nsdate按formatter格式转成NSString
NSString *currentTimeString_1 = [formatter stringFromDate:datenow];
NSDate *applyTimeString_1 = [formatter dateFromString:currentTimeString_1];
long nowTimeSp = (long)[applyTimeString_1 timeIntervalSince1970];
return nowTimeSp;
}
+(NSString *)stringWithNSTimerinterval:(NSTimeInterval)interval{ +(NSString *)stringWithNSTimerinterval:(NSTimeInterval)interval{
NSInteger hour = interval / (60*60);
NSInteger min = interval / 60; NSInteger min = interval / 60;
NSInteger sec = (NSInteger) interval % 60; NSInteger sec = (NSInteger) interval % 60;
return [NSString stringWithFormat:@"%02ld:%02ld",min,sec]; return [NSString stringWithFormat:@"%02ld:%02ld:%02ld",hour,min,sec];
} }
@@ -0,0 +1,48 @@
//
// GiGaLocalNotificationManager.h
// GIGA
//
// Created by lianxiang on 2018/8/24.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>
@interface GiGaLocalNotificationManager : NSObject<UNUserNotificationCenterDelegate>
/**
本地推送管理中心
*/
+(GiGaLocalNotificationManager*)localNotifiationCenter;
/**
发送本地通知
ios 8 后 iOS10 前
@param alertBoday 通知显示内容
@param timeInterval 设置通知发送时间,单位秒
@param alertAction 解锁滑动时事件
@param identifier ios 10 即是Identifier iOS8 是userInfo key value 值
*/
-(void)sendLocalNotification:(NSString *)alertBoday fireTimeInterval:(NSTimeInterval )timeInterval alertAction:(NSString *)alertAction withIdentifier:(NSString *)identifier;
/**
删除当前程序注册的所有通知 ios 8 后 iOS10 前
*/
-(void)cancelAllLocalNoitification;
/**
删除指定的通知,一般用于取消重复的通知或者还没有被调用的通知,先获取通知,再遍历根据条件去删除(条件是 UserInfo 的值,是发送通知时所携带的参数) ios 8 后 iOS10 前
*/
-(void)cancelLocalNitificationByUserInfowithIdentifier:(NSString *)identifier;
/**
iOS 8 收到本地通知 iOS10通过 UNUserNotificationCenterDelegate实现
*/
-(void)didResaveloaclNitification:(UILocalNotification *)localNitification;
//处理通知。。
@end
@@ -0,0 +1,164 @@
//
// GiGaLocalNotificationManager.m
// GIGA
//
// Created by lianxiang on 2018/8/24.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "GiGaLocalNotificationManager.h"
@implementation GiGaLocalNotificationManager
+(GiGaLocalNotificationManager*)localNotifiationCenter{
static GiGaLocalNotificationManager *center = nil;
static dispatch_once_t once;
dispatch_once(&once, ^{
center = [[self alloc] init];
});
return center;
}
-(void)sendLocalNotification:(NSString *)alertBoday fireTimeInterval:(NSTimeInterval )timeInterval alertAction:(NSString *)alertAction withIdentifier:(NSString *)identifier{
if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = alertAction;
content.body = alertBoday;
content.sound = [UNNotificationSound defaultSound];
//content.sound = UNNotificationSound
//通知附件 音<10M p3 p4 ,视频<50M pmeg mpeg4 图片<5M
NSURL *imageUrl = [[NSBundle mainBundle] URLForResource:@"MaskTime" withExtension:@"png"];
UNNotificationAttachment *attach = [UNNotificationAttachment attachmentWithIdentifier:@"photo" URL:imageUrl options:nil error:nil];
NSURL *audioUrl = [[NSBundle mainBundle] URLForResource:@"pomodoSound" withExtension:@"m4a"];
UNNotificationAttachment *attachAudio = [UNNotificationAttachment attachmentWithIdentifier:@"audio" URL:audioUrl options:nil error:nil];
NSURL *vedioUrl = [[NSBundle mainBundle] URLForResource:@"emojizone" withExtension:@"mp4"];
UNNotificationAttachment *vedioAudio = [UNNotificationAttachment attachmentWithIdentifier:@"vedio" URL:vedioUrl options:nil error:nil];
content.attachments = @[attach,attachAudio,vedioAudio];
//延迟通知 第一个参数是重复的时间间隔,最小60s,第二个参数是是否重复。
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) {
GILog(@"成功添加推送");
}];
} else {
// Fallback on earlier versions
//ios8
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = alertBoday;
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
localNotification.alertAction = alertAction;
localNotification.applicationIconBadgeNumber = 1;
localNotification.soundName = UILocalNotificationDefaultSoundName;
//localNotification.alertLaunchImage = @"MaskTime.png";
localNotification.userInfo = @{identifier:identifier};
//根据设定时间发送通知
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
}
-(void)cancelAllLocalNoitification
{
if (@available(iOS 10.0, *)) {
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
} else {
// Fallback on earlier versions
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
}
-(void)cancelLocalNitificationByUserInfowithIdentifier:(NSString *)identifier{
if (@available(iOS 10.0, *)) {
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[identifier]];
} else {
// Fallback on earlier versions
NSArray *notifiArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *local in notifiArray) {
//将来可以根据UserInfo的值,来查看这个是否是你想要删除的通知
if (local.userInfo) {
//删除单个通知
NSDictionary *useinfo = local.userInfo;
NSString *timefalg = useinfo[identifier];
if ([timefalg isEqualToString:identifier] ) {
[[UIApplication sharedApplication]cancelLocalNotification:local];
}
}
}
}
}
//将通知传递给前台运行的app
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
API_AVAILABLE(ios(10.0)){
NSDictionary * userInfo = notification.request.content.userInfo;
UNNotificationRequest *request = notification.request; // 收到推送的请求
UNNotificationContent *content = request.content; // 收到推送的消息内容
NSNumber *badge = content.badge; // 推送消息的角标
NSString *body = content.body; // 推送消息体
UNNotificationSound *sound = content.sound; // 推送消息的声音
NSString *subtitle = content.subtitle; // 推送消息的副标题
NSString *title = content.title; // 推送消息的标题
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
// 远程推送通知在AppDelegate+ThirdParty 中处理
NSLog(@"iOS10 前台 收到远程通知:%@", body);
} else {
// 判断为本地通知
NSLog(@"iOS10 前台 收到本地通知:{\\\\nbody:%@\\\\ntitle:%@,\\\\nsubtitle:%@,\\\\nbadge%@\\\\nsound%@\\\\nuserInfo%@\\\\n}",body,title,subtitle,badge,sound,userInfo);
[self showAlert:title message:body];
}
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
}
//将用户对通知响应结果告诉app
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
API_AVAILABLE(ios(10.0)){
GILog(@"ios10用户点击通知栏相应");
completionHandler();
}
//
-(void)didResaveloaclNitification:(UILocalNotification *)localNitification
{
//NSDictionary * userInfo = localNitification.userInfo;
NSString *title = localNitification.alertTitle;
NSString *message = localNitification.alertBody;
[self showAlert:title message:message];
GILog(@"用户点击通知栏相应");
}
-(void)showAlert:(NSString *)title message:(NSString *)message
{
[[UIApplication sharedApplication].keyWindow.rootViewController jxt_showAlertWithTitle:title message:message appearanceProcess:^(JXTAlertController * _Nonnull alertMaker) {
alertMaker.addActionCancelTitle(@"知道了");
} actionsBlock:^(NSInteger buttonIndex, UIAlertAction * _Nonnull action, JXTAlertController * _Nonnull alertSelf) {
}];
}
@end
@@ -0,0 +1,138 @@
//
// JXTAlertController.h
// JXTAlertManager
//
// Created by JXT on 2016/12/22.
// Copyright © 2016年 JXT. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
#pragma mark - I.JXTAlertController构造
@class JXTAlertController;
/**
JXTAlertController: alertAction配置链
@param title 标题
@return JXTAlertController对象
*/
typedef JXTAlertController * _Nonnull (^JXTAlertActionTitle)(NSString *title);
/**
JXTAlertController: alert按钮执行回调
@param buttonIndex 按钮index(根据添加action的顺序)
@param action UIAlertAction对象
@param alertSelf 本类对象
*/
typedef void (^JXTAlertActionBlock)(NSInteger buttonIndex, UIAlertAction *action, JXTAlertController *alertSelf);
/**
JXTAlertController 简介:
1.针对系统UIAlertController封装,支持iOS8及以上
2.关于iOS9之后的`preferredAction`属性用法:
`alertController.preferredAction = alertController.actions[0];`
效果为将已存在的某个action字体加粗,原cancel样式的加粗字体成为deafult样式,cancel样式的action仍然排列在最下
总体意义不大,且仅限于`UIAlertControllerStyleAlert`actionSheet无效,功能略微鸡肋,不再单独封装
3.关于`addTextFieldWithConfigurationHandler:`方法:
该方法同样仅限于`UIAlertControllerStyleAlert`使用,使用场景较为局限,推荐直接调用,不再针对封装
4.关于自定义按钮字体或者颜色,可以利用kvc间接访问这些私有属性,但是不推荐
`[alertAction setValue:[UIColor grayColor] forKey:@"titleTextColor"]`
*/
NS_CLASS_AVAILABLE_IOS(8_0) @interface JXTAlertController : UIAlertController
/**
JXTAlertController: 禁用alert弹出动画,默认执行系统的默认弹出动画
*/
- (void)alertAnimateDisabled;
/**
JXTAlertController: alert弹出后,可配置的回调
*/
@property (nullable, nonatomic, copy) void (^alertDidShown)(void);
/**
JXTAlertController: alert关闭后,可配置的回调
*/
@property (nullable, nonatomic, copy) void (^alertDidDismiss)(void);
/**
JXTAlertController: 设置toast模式展示时间:如果alert未添加任何按钮,将会以toast样式展示,这里设置展示时间,默认1s
*/
@property (nonatomic, assign) NSTimeInterval toastStyleDuration; //deafult jxt_alertShowDurationDefault = 1s
/**
JXTAlertController: 链式构造alert视图按钮,添加一个alertAction按钮,默认样式,参数为标题
@return JXTAlertController对象
*/
- (JXTAlertActionTitle)addActionDefaultTitle;
/**
JXTAlertController: 链式构造alert视图按钮,添加一个alertAction按钮,取消样式,参数为标题(warning:一个alert该样式只能添加一次!!!)
@return JXTAlertController对象
*/
- (JXTAlertActionTitle)addActionCancelTitle;
/**
JXTAlertController: 链式构造alert视图按钮,添加一个alertAction按钮,警告样式,参数为标题
@return JXTAlertController对象
*/
- (JXTAlertActionTitle)addActionDestructiveTitle;
@end
#pragma mark - II.UIViewController扩展使用JXTAlertController
/**
JXTAlertController: alert构造块
@param alertMaker JXTAlertController配置对象
*/
typedef void(^JXTAlertAppearanceProcess)(JXTAlertController *alertMaker);
@interface UIViewController (JXTAlertController)
/**
JXTAlertController: show-alert(iOS8)
@param title title
@param message message
@param appearanceProcess alert配置过程
@param actionBlock alert点击响应回调
*/
- (void)jxt_showAlertWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess
actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0);
/**
JXTAlertController: show-actionSheet(iOS8)
@param title title
@param message message
@param appearanceProcess actionSheet配置过程
@param actionBlock actionSheet点击响应回调
*/
- (void)jxt_showActionSheetWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess
actionsBlock:(nullable JXTAlertActionBlock)actionBlock NS_AVAILABLE_IOS(8_0);
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,216 @@
//
// JXTAlertController.m
// JXTAlertManager
//
// Created by JXT on 2016/12/22.
// Copyright © 2016年 JXT. All rights reserved.
//
#import "JXTAlertController.h"
//toast默认展示时间
static NSTimeInterval const JXTAlertShowDurationDefault = 1.0f;
#pragma mark - I.AlertActionModel
@interface JXTAlertActionModel : NSObject
@property (nonatomic, copy) NSString * title;
@property (nonatomic, assign) UIAlertActionStyle style;
@end
@implementation JXTAlertActionModel
- (instancetype)init
{
if (self = [super init]) {
self.title = @"";
self.style = UIAlertActionStyleDefault;
}
return self;
}
@end
#pragma mark - II.JXTAlertController
/**
AlertActions配置
@param actionBlock JXTAlertActionBlock
*/
typedef void (^JXTAlertActionsConfig)(JXTAlertActionBlock actionBlock);
@interface JXTAlertController ()
//JXTAlertActionModel数组
@property (nonatomic, strong) NSMutableArray <JXTAlertActionModel *>* jxt_alertActionArray;
//是否操作动画
@property (nonatomic, assign) BOOL jxt_setAlertAnimated;
//action配置
- (JXTAlertActionsConfig)alertActionsConfig;
@end
@implementation JXTAlertController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
if (self.alertDidDismiss) {
self.alertDidDismiss();
}
}
- (void)dealloc
{
// NSLog(@"test-dealloc");
}
#pragma mark - Private
//action-title数组
- (NSMutableArray<JXTAlertActionModel *> *)jxt_alertActionArray
{
if (_jxt_alertActionArray == nil) {
_jxt_alertActionArray = [NSMutableArray array];
}
return _jxt_alertActionArray;
}
//action配置
- (JXTAlertActionsConfig)alertActionsConfig
{
return ^(JXTAlertActionBlock actionBlock) {
if (self.jxt_alertActionArray.count > 0)
{
//创建action
__weak typeof(self)weakSelf = self;
[self.jxt_alertActionArray enumerateObjectsUsingBlock:^(JXTAlertActionModel *actionModel, NSUInteger idx, BOOL * _Nonnull stop) {
UIAlertAction *alertAction = [UIAlertAction actionWithTitle:actionModel.title style:actionModel.style handler:^(UIAlertAction * _Nonnull action) {
__strong typeof(weakSelf)strongSelf = weakSelf;
if (actionBlock) {
actionBlock(idx, action, strongSelf);
}
}];
//可利用这个改变字体颜色,但是不推荐!!!
// [alertAction setValue:[UIColor grayColor] forKey:@"titleTextColor"];
//action作为self元素,其block实现如果引用本类指针,会造成循环引用
[self addAction:alertAction];
}];
}
else
{
NSTimeInterval duration = self.toastStyleDuration > 0 ? self.toastStyleDuration : JXTAlertShowDurationDefault;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:!(self.jxt_setAlertAnimated) completion:NULL];
});
}
};
}
#pragma mark - Public
- (instancetype)initAlertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle
{
if (!(title.length > 0) && (message.length > 0) && (preferredStyle == UIAlertControllerStyleAlert)) {
title = @"";
}
self = [[self class] alertControllerWithTitle:title message:message preferredStyle:preferredStyle];
if (!self) return nil;
self.jxt_setAlertAnimated = NO;
self.toastStyleDuration = JXTAlertShowDurationDefault;
return self;
}
- (void)alertAnimateDisabled
{
self.jxt_setAlertAnimated = YES;
}
- (JXTAlertActionTitle)addActionDefaultTitle
{
//该block返回值不是本类属性,只是局部变量,不会造成循环引用
return ^(NSString *title) {
JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init];
actionModel.title = title;
actionModel.style = UIAlertActionStyleDefault;
[self.jxt_alertActionArray addObject:actionModel];
return self;
};
}
- (JXTAlertActionTitle)addActionCancelTitle
{
return ^(NSString *title) {
JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init];
actionModel.title = title;
actionModel.style = UIAlertActionStyleCancel;
[self.jxt_alertActionArray addObject:actionModel];
return self;
};
}
- (JXTAlertActionTitle)addActionDestructiveTitle
{
return ^(NSString *title) {
JXTAlertActionModel *actionModel = [[JXTAlertActionModel alloc] init];
actionModel.title = title;
actionModel.style = UIAlertActionStyleDestructive;
[self.jxt_alertActionArray addObject:actionModel];
return self;
};
}
@end
#pragma mark - III.UIViewController扩展
@implementation UIViewController (JXTAlertController)
- (void)jxt_showAlertWithPreferredStyle:(UIAlertControllerStyle)preferredStyle title:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock
{
if (appearanceProcess)
{
JXTAlertController *alertMaker = [[JXTAlertController alloc] initAlertControllerWithTitle:title message:message preferredStyle:preferredStyle];
//防止nil
if (!alertMaker) {
return ;
}
//加工链
appearanceProcess(alertMaker);
//配置响应
alertMaker.alertActionsConfig(actionBlock);
// alertMaker.alertActionsConfig(^(NSInteger buttonIndex, UIAlertAction *action){
// if (actionBlock) {
// actionBlock(buttonIndex, action);
// }
// });
if (alertMaker.alertDidShown)
{
[self presentViewController:alertMaker animated:!(alertMaker.jxt_setAlertAnimated) completion:^{
alertMaker.alertDidShown();
}];
}
else
{
[self presentViewController:alertMaker animated:!(alertMaker.jxt_setAlertAnimated) completion:NULL];
}
}
}
- (void)jxt_showAlertWithTitle:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock
{
[self jxt_showAlertWithPreferredStyle:UIAlertControllerStyleAlert title:title message:message appearanceProcess:appearanceProcess actionsBlock:actionBlock];
}
- (void)jxt_showActionSheetWithTitle:(NSString *)title message:(NSString *)message appearanceProcess:(JXTAlertAppearanceProcess)appearanceProcess actionsBlock:(JXTAlertActionBlock)actionBlock
{
[self jxt_showAlertWithPreferredStyle:UIAlertControllerStyleActionSheet title:title message:message appearanceProcess:appearanceProcess actionsBlock:actionBlock];
}
@end
+301
View File
@@ -0,0 +1,301 @@
//
// JXTAlertView.h
// JXTAlertManager
//
// Created by JXT on 2016/12/20.
// Copyright © 2016年 JXT. All rights reserved.
//
#import <UIKit/UIKit.h>
#define jxt_dispatch_main_async_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}
/**
回调主线程(显示alert必须在主线程执行)
@param block 执行块
*/
static inline void jxt_getSafeMainQueue(_Nonnull dispatch_block_t block)
{
jxt_dispatch_main_async_safe(block);
}
/**
alert按钮执行回调
@param buttonIndex 按钮index
*/
typedef void (^JXTAlertClickBlock)(NSInteger buttonIndex);
// MARK: 1.常规的alert
/**
* JXTAlertView: 两个按钮alert
*/
void jxt_showAlertTwoButton(NSString * _Nullable title,
NSString * _Nullable message,
NSString * _Nullable cancelButtonTitle,
JXTAlertClickBlock _Nullable cancelBlock,
NSString * _Nullable otherButtonTitle,
JXTAlertClickBlock _Nullable otherBlock);
/**
* JXTAlertView: 一个按钮alert
*/
void jxt_showAlertOneButton(NSString * _Nullable title,
NSString * _Nullable message,
NSString * _Nullable cancelButtonTitle,
JXTAlertClickBlock _Nullable cancelBlock);
/**
* JXTAlertView: 一个固定按钮alert
*/
void jxt_showAlertTitle(NSString * _Nullable title);
/**
* JXTAlertView: 一个固定按钮alert
*/
void jxt_showAlertMessage(NSString * _Nullable message);
/**
* JXTAlertView: 一个固定按钮alert
*/
void jxt_showAlertTitleMessage(NSString * _Nullable title,
NSString * _Nullable message);
// MARK: 2.无按钮toast
/**
* JXTAlertView: 无按钮toast,支持自定义关闭回调
*/
void jxt_showToastTitleMessageDismiss(NSString * _Nullable title,
NSString * _Nullable message,
NSTimeInterval duration,
JXTAlertClickBlock _Nullable dismissCompletion);
/**
* JXTAlertView: 无按钮toast,支持自定义关闭回调
*/
void jxt_showToastTitleDismiss(NSString * _Nullable title,
NSTimeInterval duration,
JXTAlertClickBlock _Nullable dismissCompletion);
/**
* JXTAlertView: 无按钮toast,支持自定义关闭回调
*/
void jxt_showToastMessageDismiss(NSString * _Nullable message,
NSTimeInterval duration,
JXTAlertClickBlock _Nullable dismissCompletion);
/**
* JXTAlertView: 无按钮toast
*/
void jxt_showToastTitle(NSString * _Nullable title,
NSTimeInterval duration);
/**
* JXTAlertView: 无按钮toast
*/
void jxt_showToastMessage(NSString * _Nullable message,
NSTimeInterval duration);
// MARK: 3.文字HUD,代码执行关闭
/**
* JXTAlertView: 文字HUDjxt_dismissHUD()执行关闭
*/
void jxt_showTextHUDTitleMessage(NSString * _Nullable title,
NSString * _Nullable message);
/**
* JXTAlertView: 文字HUDjxt_dismissHUD()执行关闭
*/
void jxt_showTextHUDTitle(NSString * _Nullable title);
/**
* JXTAlertView: 文字HUDjxt_dismissHUD()执行关闭
*/
void jxt_showTextHUDMessage(NSString * _Nullable message);
// MARK: 4.loadHUD,代码执行关闭
/**
* JXTAlertView: loadHUDjxt_dismissHUD()执行关闭
*/
void jxt_showLoadingHUDTitleMessage(NSString * _Nullable title,
NSString * _Nullable message);
/**
* JXTAlertView: loadHUDjxt_dismissHUD()执行关闭
*/
void jxt_showLoadingHUDTitle(NSString * _Nullable title);
/**
* JXTAlertView: loadHUDjxt_dismissHUD()执行关闭
*/
void jxt_showLoadingHUDMessage(NSString * _Nullable message);
// MARK: 5.ProgressHUD,代码执行关闭
/**
* JXTAlertView: ProgressHUDjxt_dismissHUD()执行关闭
*/
void jxt_showProgressHUDTitleMessage(NSString * _Nullable title,
NSString * _Nullable message);
/**
* JXTAlertView: ProgressHUDjxt_dismissHUD()执行关闭
*/
void jxt_showProgressHUDTitle(NSString * _Nullable title);
/**
* JXTAlertView: ProgressHUDjxt_dismissHUD()执行关闭
*/
void jxt_showProgressHUDMessage(NSString * _Nullable message);
/**
* JXTAlertView: ProgressHUD,设置进度值
*/
void jxt_setHUDProgress(float progress);
// MARK: 6.HUD公用
/**
* JXTAlertView: 设置HUD成功状态
*/
void jxt_setHUDSuccessTitleMessage(NSString * _Nullable title,
NSString * _Nullable message);
/**
* JXTAlertView: 设置HUD成功状态
*/
void jxt_setHUDSuccessTitle(NSString * _Nullable title);
/**
* JXTAlertView: 设置HUD成功状态
*/
void jxt_setHUDSuccessMessage(NSString * _Nullable message);
/**
* JXTAlertView: 设置HUD失败状态
*/
void jxt_setHUDFailTitleMessage(NSString * _Nullable title,
NSString * _Nullable message);
/**
* JXTAlertView: 设置HUD失败状态
*/
void jxt_setHUDFailTitle(NSString * _Nullable title);
/**
* JXTAlertView: 设置HUD失败状态
*/
void jxt_setHUDFailMessage(NSString * _Nullable message);
/**
* JXTAlertView: 关闭HUD
*/
void jxt_dismissHUD(void);
/**
JXTAlertView 简介:
开发调试使用简易alert/HUD工具
部分提供C函数方便使用,所有show方法的C函数均默认回调主线程
*/
@interface JXTAlertView : UIAlertView
/**
JXTAlertView: 最多支持两个按钮的alert
@param title title
@param message message
@param cancelButtonTitle 取消按钮标题
@param otherButtonTitle 其他按钮标题
@param cancelBlock 取消按钮回调
@param otherBlock 其他按钮回调
*/
+ (void)showAlertViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitle:(nullable NSString *)otherButtonTitle
cancelButtonBlock:(nullable JXTAlertClickBlock)cancelBlock
otherButtonBlock:(nullable JXTAlertClickBlock)otherBlock;
/**
JXTAlertView: 不定数量按钮alert
@param title title
@param message message
@param cancelButtonTitle 取消按钮标题
@param buttonIndexBlock 按钮回调
@param otherButtonTitles 其他按钮标题列表
*/
+ (void)showAlertViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
buttonIndexBlock:(nullable JXTAlertClickBlock)buttonIndexBlock
otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/**
JXTAlertView: 不带按钮自动消失的toast
@param title title
@param message message
@param duration 显示时间
@param dismissCompletion 关闭后回调
*/
+ (void)showToastViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
duration:(NSTimeInterval)duration
dismissCompletion:(nullable JXTAlertClickBlock)dismissCompletion;
/**
JXTAlertView: 文字HUD
@param title title
@param message message
*/
+ (void)showTextHUDWithTitle:(nullable NSString *)title
message:(nullable NSString *)message;
/**
JXTAlertView: loadHUD
@param title title
@param message message
*/
+ (void)showLoadingHUDWithTitle:(nullable NSString *)title
message:(nullable NSString *)message;
/**
JXTAlertView: progressHUD
@param title title
@param message message
*/
+ (void)showProgressHUDWithTitle:(nullable NSString *)title
message:(nullable NSString *)message;
/**
JXTAlertView: progressHUD,进度条进度值
@param progress 进度值
*/
+ (void)setHUDProgress:(float)progress;
/**
JXTAlertView: HUD公用方法,设置成功状态
@param title title
@param message message
*/
+ (void)setHUDSuccessStateWithTitle:(nullable NSString *)title
message:(nullable NSString *)message;
/**
JXTAlertView: HUD公用方法,设置失败状态
@param title title
@param message message
*/
+ (void)setHUDFailStateWithTitle:(nullable NSString *)title
message:(nullable NSString *)message;
/**
JXTAlertView: HUD公用方法,关闭HUD
*/
+ (void)dismissHUD;
@end
+544
View File
@@ -0,0 +1,544 @@
//
// JXTAlertView.m
// JXTAlertManager
//
// Created by JXT on 2016/12/20.
// Copyright © 2016年 JXT. All rights reserved.
//
#import "JXTAlertView.h"
#pragma mark - Private
/**
* 取消按钮默认标题
*/
static NSString *const JXTCancelButtonTitleDefault = @"确定";
/**
* toast默认展示时间,当设置为0时,用该值
*/
static NSTimeInterval const JXTToastShowDurationDefault = 1.0f;
/**
* alertView子视图key
*/
static NSString *const JXTAlertViewAccessoryViewKey = @"accessoryView";
#pragma mark - Public
//1.常规alert
void jxt_showAlertTwoButton(NSString *title, NSString *message, NSString *cancelButtonTitle, JXTAlertClickBlock cancelBlock, NSString *otherButtonTitle, JXTAlertClickBlock otherBlock)
{
jxt_getSafeMainQueue(^{
[JXTAlertView showAlertViewWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitle:otherButtonTitle cancelButtonBlock:cancelBlock otherButtonBlock:otherBlock];
});
}
void jxt_showAlertOneButton(NSString *title, NSString *message, NSString *cancelButtonTitle, JXTAlertClickBlock cancelBlock)
{
jxt_showAlertTwoButton(title, message, cancelButtonTitle, cancelBlock, nil, NULL);
}
void jxt_showAlertTitle(NSString *title)
{
jxt_showAlertTwoButton(title, nil, JXTCancelButtonTitleDefault, NULL, nil, NULL);
}
void jxt_showAlertMessage(NSString *message)
{
jxt_showAlertTwoButton(@"", message, JXTCancelButtonTitleDefault, NULL, nil, NULL);
}
void jxt_showAlertTitleMessage(NSString *title, NSString *message)
{
jxt_showAlertTwoButton(title, message, JXTCancelButtonTitleDefault, NULL, nil, NULL);
}
//2.无按钮toast
void jxt_showToastTitleMessageDismiss(NSString *title, NSString *message, NSTimeInterval duration, JXTAlertClickBlock dismissCompletion)
{
jxt_getSafeMainQueue(^{
[JXTAlertView showToastViewWithTitle:title message:message duration:duration dismissCompletion:dismissCompletion];
});
}
void jxt_showToastTitleDismiss(NSString *title, NSTimeInterval duration, JXTAlertClickBlock dismissCompletion)
{
jxt_showToastTitleMessageDismiss(title, nil, duration, dismissCompletion);
}
void jxt_showToastMessageDismiss(NSString *message, NSTimeInterval duration, JXTAlertClickBlock dismissCompletion)
{
jxt_showToastTitleMessageDismiss(@"", message, duration, dismissCompletion);
}
void jxt_showToastTitle(NSString *title, NSTimeInterval duration)
{
jxt_showToastTitleMessageDismiss(title, nil, duration, NULL);
}
void jxt_showToastMessage(NSString *message, NSTimeInterval duration)
{
jxt_showToastTitleMessageDismiss(@"", message, duration, NULL);
}
//3.文字HUD
void jxt_showTextHUDTitleMessage(NSString *title, NSString *message)
{
jxt_getSafeMainQueue(^{
[JXTAlertView showTextHUDWithTitle:title message:message];
});
}
void jxt_showTextHUDTitle(NSString *title)
{
jxt_showTextHUDTitleMessage(title, nil);
}
void jxt_showTextHUDMessage(NSString *message)
{
jxt_showTextHUDTitleMessage(@"", message);
}
//4.loadHUD
void jxt_showLoadingHUDTitleMessage(NSString *title, NSString *message)
{
jxt_getSafeMainQueue(^{
[JXTAlertView showLoadingHUDWithTitle:title message:message];
});
}
void jxt_showLoadingHUDTitle(NSString *title)
{
jxt_showLoadingHUDTitleMessage(title, nil);
}
void jxt_showLoadingHUDMessage(NSString *message)
{
jxt_showLoadingHUDTitleMessage(@"", message);
}
//5.progressHUD
void jxt_showProgressHUDTitleMessage(NSString *title, NSString *message)
{
jxt_getSafeMainQueue(^{
[JXTAlertView showProgressHUDWithTitle:title message:message];
});
}
void jxt_showProgressHUDTitle(NSString *title)
{
jxt_showProgressHUDTitleMessage(title, nil);
}
void jxt_showProgressHUDMessage(NSString *message)
{
jxt_showProgressHUDTitleMessage(@"", message);
}
void jxt_setHUDProgress(float progress)
{
[JXTAlertView setHUDProgress:progress];
}
//6.HUD公用
//成功状态
void jxt_setHUDSuccessTitleMessage(NSString *title, NSString *message)
{
jxt_getSafeMainQueue(^{
[JXTAlertView setHUDSuccessStateWithTitle:title message:message];
});
}
void jxt_setHUDSuccessTitle(NSString *title)
{
jxt_setHUDSuccessTitleMessage(title, nil);
}
void jxt_setHUDSuccessMessage(NSString *message)
{
jxt_setHUDSuccessTitleMessage(@"", message);
}
//失败状态
void jxt_setHUDFailTitleMessage(NSString *title, NSString *message)
{
jxt_getSafeMainQueue(^{
[JXTAlertView setHUDFailStateWithTitle:title message:message];
});
}
void jxt_setHUDFailTitle(NSString *title)
{
jxt_setHUDFailTitleMessage(title, nil);
}
void jxt_setHUDFailMessage(NSString *message)
{
jxt_setHUDFailTitleMessage(@"", message);
}
//关闭HUD
void jxt_dismissHUD(void)
{
jxt_getSafeMainQueue(^{
[JXTAlertView dismissHUD];
});
}
#pragma mark - define
/**
* JXTAlertType
*/
typedef NS_ENUM(NSInteger, JXTAlertType) {
JXTAlertTypeNormal,
JXTAlertTypeToast,
JXTAlertTypeHUD
};
/**
* JXTAlertHUDType
*/
typedef NS_ENUM(NSInteger, JXTAlertHUDType) {
JXTAlertHUDTypeTextOnly,
JXTAlertHUDTypeLoading,
JXTAlertHUDTypeProgress
};
@interface JXTAlertView () <UIAlertViewDelegate>
//block
@property (nonatomic, copy) JXTAlertClickBlock buttonClickBlock;
@property (nonatomic, copy) JXTAlertClickBlock completionBlock;
//type
@property (nonatomic, assign) JXTAlertType alertType;
@property (nonatomic, assign) JXTAlertHUDType alertHUDType;
//HUD附件
@property (nonatomic, strong) UIActivityIndicatorView *indicatorView;
@property (nonatomic, strong) UIProgressView *progressView;
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle, ... NS_REQUIRES_NIL_TERMINATION;
@end
@implementation JXTAlertView
#pragma mark - Init
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle, ...
{
self = [self initWithTitle:title message:message delegate:self cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitle, nil];
if (!self) return nil;
return self;
}
#pragma mark - shared
static JXTAlertView *__jxt_commonHUD = nil;
+ (instancetype)sharedCommonHUDWithHUDType:(JXTAlertHUDType)HUDType
{
if (__jxt_commonHUD == nil)
{
__jxt_commonHUD = [[JXTAlertView alloc] initWithTitle:nil message:nil cancelButtonTitle:nil otherButtonTitle:nil];
//
__jxt_commonHUD.alertType = JXTAlertTypeHUD;
__jxt_commonHUD.alertHUDType = HUDType;
switch (HUDType)
{
case JXTAlertHUDTypeTextOnly:
break;
case JXTAlertHUDTypeLoading:
{
//添加指示器
UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicatorView.color = [UIColor blackColor];
[indicatorView startAnimating];
__jxt_commonHUD.indicatorView = indicatorView;
//强制添加子视图
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
[__jxt_commonHUD setValue:indicatorView forKey:JXTAlertViewAccessoryViewKey];
}
else
{
[__jxt_commonHUD addSubview:indicatorView];
}
break;
}
case JXTAlertHUDTypeProgress:
{
//添加进度条
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.progressTintColor = [UIColor blackColor];
progressView.progress = 0.0;
__jxt_commonHUD.progressView = progressView;
//强制添加子视图
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
[__jxt_commonHUD setValue:progressView forKey:JXTAlertViewAccessoryViewKey];
}
else
{
[__jxt_commonHUD addSubview:progressView];
}
break;
}
}
}
return __jxt_commonHUD;
}
+ (JXTAlertView *)sharedCommonHUD
{
return __jxt_commonHUD;
}
+ (void)clearCommonHUD
{
__jxt_commonHUD = nil;
}
//重写setValue:forUndefinedKey:方法,处理不存在的key赋值,防止崩溃
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
NSLog(@"key: %@ 不存在", key);
}
- (id)valueForUndefinedKey:(NSString *)key
{
NSLog(@"value: %@ 不存在", key);
return nil;
}
#pragma mark - Methods
//1.常规alert
+ (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle cancelButtonBlock:(JXTAlertClickBlock)cancelBlock otherButtonBlock:(JXTAlertClickBlock)otherBlock
{
if (!(title.length > 0) && message.length > 0) {
title = @"";
}
JXTAlertView *alertView = [[JXTAlertView alloc] initWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitle:otherButtonTitle, nil];
alertView.alertType = JXTAlertTypeNormal;
alertView.buttonClickBlock = ^(NSInteger buttonIndex){
if (buttonIndex == 0)
{
if (cancelBlock) {
cancelBlock(buttonIndex);
}
}
else if (buttonIndex == 1)
{
if (otherBlock) {
otherBlock(buttonIndex);
}
}
};
[alertView show];
}
//不定按钮
+ (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)message cancelButtonTitle:(NSString *)cancelButtonTitle buttonIndexBlock:(JXTAlertClickBlock)buttonIndexBlock otherButtonTitles:(NSString *)otherButtonTitles, ...
{
if (!(title.length > 0) && message.length > 0) {
title = @"";
}
JXTAlertView *alertView = [[JXTAlertView alloc] initWithTitle:title message:message cancelButtonTitle:cancelButtonTitle otherButtonTitle:nil];
alertView.alertType = JXTAlertTypeNormal;
alertView.buttonClickBlock = buttonIndexBlock;
if (otherButtonTitles)
{
va_list args;//定义一个指向个数可变的参数列表指针
va_start(args, otherButtonTitles);//得到第一个可变参数地址
for (NSString *arg = otherButtonTitles; arg != nil; arg = va_arg(args, NSString *))
{
[alertView addButtonWithTitle:arg];
}
va_end(args);//置空指针
}
[alertView show];
}
//2.无按钮toast
+ (void)showToastViewWithTitle:(NSString *)title message:(NSString *)message duration:(NSTimeInterval)duration dismissCompletion:(JXTAlertClickBlock)dismissCompletion
{
if (!(title.length > 0) && message.length > 0) {
title = @"";
}
JXTAlertView *toastView = [[JXTAlertView alloc] initWithTitle:title message:message cancelButtonTitle:nil otherButtonTitle:nil];
toastView.alertType = JXTAlertTypeToast;
toastView.completionBlock = ^(NSInteger buttonIndex){
if (buttonIndex == 0)
{
if (dismissCompletion) {
dismissCompletion(buttonIndex);
}
}
};
[toastView show];
duration = duration > 0 ? duration : JXTToastShowDurationDefault;
[toastView performSelector:@selector(dismissToastView:) withObject:toastView afterDelay:duration];
}
- (void)dismissToastView:(UIAlertView *)toastView
{
[toastView dismissWithClickedButtonIndex:0 animated:YES];
}
//3.文字HUD
+ (void)showTextHUDWithTitle:(NSString *)title message:(NSString *)message
{
if (!(title.length > 0) && message.length > 0) {
title = @"";
}
JXTAlertView *textHUD = [JXTAlertView sharedCommonHUDWithHUDType:JXTAlertHUDTypeTextOnly];
textHUD.title = title;
textHUD.message = message;
// textHUD.delegate = nil;
[textHUD show];
}
//4.loadHUD
+ (void)showLoadingHUDWithTitle:(NSString *)title message:(NSString *)message
{
if (!(title.length > 0) && message.length > 0) {
title = @"";
}
JXTAlertView *loadingHUD = [JXTAlertView sharedCommonHUDWithHUDType:JXTAlertHUDTypeLoading];
loadingHUD.title = title;
loadingHUD.message = message;
[loadingHUD show];
}
//5.progressHUD
+ (void)showProgressHUDWithTitle:(NSString *)title message:(NSString *)message
{
if (!(title.length > 0) && message.length > 0) {
title = @"";
}
JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUDWithHUDType:JXTAlertHUDTypeProgress];
alertHUD.title = title;
alertHUD.message = message;
[alertHUD show];
}
+ (void)setHUDProgress:(float)progress
{
JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD];
[alertHUD.progressView setProgress:progress animated:YES];
if (progress >= 1.0) {
[alertHUD.progressView setProgress:1];
// [alertHUD dismissWithClickedButtonIndex:0 animated:YES];
}
}
//6.HUD公用
+ (void)setHUDSuccessStateWithTitle:(NSString *)title message:(NSString *)message
{
JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD];
alertHUD.title = title;
alertHUD.message = message;
switch (alertHUD.alertHUDType)
{
case JXTAlertHUDTypeTextOnly:
break;
case JXTAlertHUDTypeLoading:
{
[alertHUD.indicatorView stopAnimating];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
[alertHUD setValue:nil forKey:JXTAlertViewAccessoryViewKey];
}
else
{
[alertHUD.indicatorView removeFromSuperview];
}
alertHUD.indicatorView = nil;
break;
}
case JXTAlertHUDTypeProgress:
{
[alertHUD.progressView setProgress:1 animated:YES];
break;
}
}
}
+ (void)setHUDFailStateWithTitle:(NSString *)title message:(NSString *)message
{
JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD];
alertHUD.title = title;
alertHUD.message = message;
switch (alertHUD.alertHUDType)
{
case JXTAlertHUDTypeTextOnly:
break;
case JXTAlertHUDTypeLoading:
{
[alertHUD.indicatorView stopAnimating];
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
[alertHUD setValue:nil forKey:JXTAlertViewAccessoryViewKey];
}
else
{
[alertHUD.indicatorView removeFromSuperview];
}
alertHUD.indicatorView = nil;
break;
}
case JXTAlertHUDTypeProgress:
{
[alertHUD.progressView setProgress:0 animated:YES];
break;
}
}
}
+ (void)dismissHUD
{
JXTAlertView *alertHUD = [JXTAlertView sharedCommonHUD];
switch (alertHUD.alertHUDType)
{
case JXTAlertHUDTypeTextOnly:
break;
case JXTAlertHUDTypeLoading:
{
[alertHUD.indicatorView stopAnimating];
alertHUD.indicatorView = nil;
break;
}
case JXTAlertHUDTypeProgress:
break;
}
[alertHUD dismissWithClickedButtonIndex:0 animated:YES];
}
#pragma mark - Delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
if (self.buttonClickBlock) {
self.buttonClickBlock(buttonIndex);
}
self.buttonClickBlock = NULL;//解除闭环
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (self.completionBlock) {
self.completionBlock(buttonIndex);
}
self.completionBlock = NULL;//解除闭环
switch (self.alertType)
{
case JXTAlertTypeNormal:
break;
case JXTAlertTypeToast:
{
//清理performSelector,防止意外情况下的内存泄漏
[NSObject cancelPreviousPerformRequestsWithTarget:alertView selector:@selector(dismissToastView:) object:alertView];
break;
}
case JXTAlertTypeHUD:
{
//清理static
[JXTAlertView clearCommonHUD];
break;
}
}
}
@end
+20
View File
@@ -0,0 +1,20 @@
//
// JXTAlertManagerHeader.h
// JXTAlertManagerDemo
//
// Created by JXT on 2016/12/22.
// Copyright © 2016年 JXT. All rights reserved.
//
#ifndef JXTAlertManagerHeader_h
#define JXTAlertManagerHeader_h
#import "JXTAlertView.h"
//以下适配,只做提示用,实际使用,如果要适配iOS7,对应方法还是需要自行适配
//不然的话,可能因为这个宏,导致bug,因为新版xcode编译,对应方法是可以使用的(因为xcode的API存在),但是实际在对应系统上,可能就崩溃了
#ifdef NSFoundationVersionNumber_iOS_8_0
#import "JXTAlertController.h"
#endif
#endif /* JXTAlertManagerHeader_h */
+1
View File
@@ -76,6 +76,7 @@
} }
-(void)dealloc{ -(void)dealloc{
NSLog(@"%s dealloc",object_getClassName(self)); NSLog(@"%s dealloc",object_getClassName(self));
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+4 -2
View File
@@ -34,11 +34,13 @@ UD_SYNC
#define USER_GUARD_DISSMISS @"userGaurdDissmiss" #define USER_GUARD_DISSMISS @"userGaurdDissmiss"
#define APP_GUARD_DISSMISS @"APPGaurdDissmiss" #define APP_GUARD_DISSMISS @"APPGaurdDissmiss"
//adView //adView
//#define APP_START_ADVIEW_PUSH @"APPStartAdviewpush"
#define APP_PUSHTO_DETAILVIEW @"appPushToDetailAdView" #define APP_PUSHTO_DETAILVIEW @"appPushToDetailAdView"
//面膜时间结束
#define kLOCALNotifiID_MASKETIMEEND @"GIGALocalNotificationMaskTimeEnd"
//app 挂起
#define kLOCALNotifiID_APPTERMINAL @"GIGALocalNotificationAppTerminal"
#define GIGARGB(R,G,B,A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A] #define GIGARGB(R,G,B,A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
#define GIGAUIColorFromRGB_A(rgbValue,alphaValue) [UIColor \ #define GIGAUIColorFromRGB_A(rgbValue,alphaValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
+2
View File
@@ -14,6 +14,8 @@
#import "GIGA.h" #import "GIGA.h"
#import "AFNetworking.h" #import "AFNetworking.h"
#import "UIView+Toast.h" #import "UIView+Toast.h"
#import "JXTAlertManagerHeader.h"
#import "Masonry.h"
#ifdef DEBUG #ifdef DEBUG
#define GILog(fmt,...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #define GILog(fmt,...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
@@ -50,7 +50,8 @@
-(void)textFieldUI{ -(void)textFieldUI{
[self.acountTextField setValue:[UIColor colorWithRed:153/255.0f green:153/255.0f blue:153/255.0f alpha:1] forKey:@"_placeholderLabel.textColor"];
//self.acountTextField.attributedPlaceholder = @"";
UIView *acountView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; UIView *acountView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
acountView.backgroundColor = [UIColor redColor]; acountView.backgroundColor = [UIColor redColor];
UIImageView *acountViewIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 16, 18)]; UIImageView *acountViewIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 16, 18)];
@@ -12,29 +12,74 @@
#import "UserGuardViewController.h" #import "UserGuardViewController.h"
#import "GiGaUserDefault.h" #import "GiGaUserDefault.h"
#import "GiGaAppGaurdVC.h" #import "GiGaAppGaurdVC.h"
#import "UIView+Toast.h"
#import "GiGaMeViewController.h" #import "GiGaMeViewController.h"
#import "GiGaAdDetailViewController.h" #import "GiGaAdDetailViewController.h"
#import "GiGaMasssagesVC.h" #import "GiGaMasssagesVC.h"
#import "Masonry.h"
#import "GiGaQuestionVC.h" #import "GiGaQuestionVC.h"
#import <AVFoundation/AVFoundation.h>
#import "GiGaLocalNotificationManager.h"
#import "AppDelegate.h"
#import "LXCountTimer.h"
#import "GiGaHelper.h"
#import <MediaPlayer/MediaPlayer.h>
@interface GiGaMaskTaskViewController () @interface GiGaMaskTaskViewController ()
{
AVAudioPlayer *_musicPalyer;
}
@property(nonatomic,strong)MaskViewBootomWaringView *waringView; @property(nonatomic,strong)MaskViewBootomWaringView *waringView;
@property(nonatomic,strong)UILabel *countLabel;
@property (strong ,nonatomic) LXCountTimer *timer;
@end @end
@implementation GiGaMaskTaskViewController @implementation GiGaMaskTaskViewController
-(UILabel *)countLabel{
if (!_countLabel) {
_countLabel = [[UILabel alloc] init];
_countLabel.textColor = [UIColor redColor];
_countLabel.text = @"30:00";
_countLabel.textAlignment = NSTextAlignmentCenter;
}
return _countLabel;
}
-(LXCountTimer *)timer{
if (!_timer) {
_timer = [[LXCountTimer alloc] init];
}
return _timer;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self startMaskTime];
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view. // Do any additional setup after loading the view.
[self setUpNav]; [self setUpNav];
[self initUI]; [self initUI];
[self addNotify]; [self addNotify];
[self creatBackGroundMusic];
} }
-(void)initUI{ -(void)initUI{
[self.view addSubview:self.countLabel];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(200);
make.width.mas_equalTo(100);
make.height.mas_equalTo(30);
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[testBtn setTitle:@"测试肤质" forState:UIControlStateNormal]; [testBtn setTitle:@"测试肤质" forState:UIControlStateNormal];
[testBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [testBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
@@ -50,12 +95,106 @@
make.height.mas_equalTo(40); make.height.mas_equalTo(40);
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-200); make.bottom.mas_equalTo(self.view.mas_bottom).offset(-200);
}]; }];
}
#pragma mark 开始计时
-(void)countTimeBegain:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second{
long nowTimestamp = [GiGaHelper getNowDateTimestamp];
long futrueTimestamp = [GiGaHelper getFutureTimetstamp:hour minute:minute second:second];
weakify(self);
[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];
if (hour == 0 && minute == 0 && second == 0) {
//面膜结束
[self maskTimeEnd];
}
}
#pragma mark 面膜时间背景音乐
-(void)creatBackGroundMusic{
//设置后台模式和锁屏模式下依然能够播放
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
//初始化音频播放器
NSError *payerError;
NSURL *musicUrl = [[NSURL alloc] initWithString:[[NSBundle mainBundle] pathForResource:@"pomodoSound" ofType:@"m4a"]] ;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicUrl error:&payerError];
player.numberOfLoops = -1;
_musicPalyer = player;
}
#pragma mark 开始面膜时间
-(void)startMaskTime{
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.isMasking = YES;
[_musicPalyer play];
[self setBackGroundPlayingInfo];
//总时间隔 s
NSTimeInterval timeInterVal = 10;
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];
[self showWaringView];
//app 前台时收到本地通知showAlert 后台时通知提醒
[[GiGaLocalNotificationManager localNotifiationCenter] sendLocalNotification:@"本地推送" fireTimeInterval:timeInterVal alertAction:@"测试面膜时间" withIdentifier:kLOCALNotifiID_MASKETIMEEND];
}
#pragma mark 设置后台锁屏样式 无效??
-(void)setBackGroundPlayingInfo{
MPMediaItemArtwork *arwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"MaskTime.png"]];
NSDictionary *dic = @{
MPMediaItemPropertyTitle:@"专辑名字专辑",
MPMediaItemPropertyAlbumArtist:@"专辑专辑专辑专辑",
MPMediaItemPropertyArtwork:arwork
};
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dic];
}
#pragma mark 面膜时间结束
-(void)maskTimeEnd{
//面膜时间结束时设置 全局变量 不再发送本地通知 提醒
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.isMasking = NO;
[_musicPalyer stop];
[self.timer destoryTimer];
} }
#pragma mark 开始测试 #pragma mark 开始测试
-(void)testBtnAcion:(UIButton *)btn{ -(void)testBtnAcion:(UIButton *)btn{
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
if (delegate.isMasking) {
return;
}
[self startMaskTime];
return ;
BOOL isUserLogin = [GiGaUserDefault isUserLogin]; BOOL isUserLogin = [GiGaUserDefault isUserLogin];
if (isUserLogin) { if (isUserLogin) {
@@ -68,7 +207,6 @@
GiGaBaseNavViewController *baseNav = [[GiGaBaseNavViewController alloc] initWithRootViewController:userlogInVC]; GiGaBaseNavViewController *baseNav = [[GiGaBaseNavViewController alloc] initWithRootViewController:userlogInVC];
[self presentViewController:baseNav animated:YES completion:nil]; [self presentViewController:baseNav animated:YES completion:nil];
} }
} }
-(void)viewDidAppear:(BOOL)animated{ -(void)viewDidAppear:(BOOL)animated{
@@ -173,7 +311,6 @@
} }
#pragma mark 个人中心 action #pragma mark 个人中心 action
-(void)rightBtnAction{ -(void)rightBtnAction{
} }
@@ -198,11 +335,6 @@
} for:UIControlEventTouchUpInside ]; } for:UIControlEventTouchUpInside ];
} }
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self showWaringView];
}
- (MaskViewBootomWaringView *)waringView{ - (MaskViewBootomWaringView *)waringView{
if (!_waringView) { if (!_waringView) {
@@ -216,14 +348,6 @@
// Dispose of any resources that can be recreated. // 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.
}
*/
@end @end
+1 -1
View File
@@ -4,7 +4,7 @@
// //
// Created by lianxiang on 2018/8/13. // Created by lianxiang on 2018/8/13.
// Copyright © 2018年 com.giga.ios. All rights reserved. // Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppDelegate.h" #import "AppDelegate.h"