#import <Foundation/Foundation.h>
#import <sqlite3.h>
//获取手机屏幕的宽、高
#define screenWidth [[UIScreen mainScreen] bounds].size.width
#define screenHeight [[UIScreen mainScreen] bounds].size.height
//字体颜色 为蓝色==帮助页面的背景色
#define blueMyColor [UIColor colorWithRed:84.0/255 green:173.0/255 blue:235.0/255 alpha:1.0]
#define colorMyButton [UIColor colorWithRed:0.0/255 green:122.0/255 blue:255.0/255 alpha:1.0]//参照IOS默认的Alert按钮颜色
#define colorPageIn [UIColor colorWithRed:27.0/255 green:73.0/255 blue:97.0/255 alpha:1.0]//深
#define colorPageCu [UIColor colorWithRed:120.0/255 green:180.0/255 blue:215.0/255 alpha:1.0]//浅
#define colorTextBack [UIColor colorWithRed:214.0/255 green:214.0/255 blue:214.0/255 alpha:1.0]//浅灰色
//全部按钮的背景
#define imgBtnHighlighted [UIImage imageNamed:@"buddy_header_bg_highlighted"]
//UI的圆角
#define YUANJIAO 8
//获取状态栏高度 貌似都使20
#define statusHeight [[UIApplication sharedApplication] statusBarFrame].size.height
//开关 字体大小
#define switchFontSize [UIFont systemFontOfSize:14]
#import "Tools.h"
#import "sys/utsname.h"
@implementation Tools
//
http://www.cnblogs.com/wendingding/p/3770052.html 关于 window 的描述
- (void)intoMainVC
{
ViewController *rootController = [[ViewController alloc]init];
//1.系统创建window
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = rootController;
//2.系统创建window的背景颜色
self.window.backgroundColor = [UIColor whiteColor];
//3.设置为主窗口 并显示出来
[self.window makeKeyAndVisible];
}
//进入下一个控制器
- (void)intoNextVC
{
NextVC *nextVc = [NextVC new];
//当根控制器不是导航栏控制器时
[self presentViewController:nextVc animated:YES completion:nil];
//当根控制器是导航栏控制器时
[self.navigationController pushViewController:nextVc animated:YES];
}
//返回到上一个控制器
- (void)backPreVC
{
//获取根控制器,和当前的做个比较
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
UIViewController *rootVC = appDelegate.window.rootViewController;
if (self == rootVC)
{
LoginViewController *login = [[LoginViewController alloc]init];
//当根控制器不是导航控制器时
{
[self presentViewController:login animated:YES completion:nil];
}
//当根控制器是导航控制器时
{
[self.navigationController popViewControllerAnimated:YES];
}
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
//返回到指定的一个控制器【导航控制器】
- (void)backTheVCWithIndex:(int)index
{
}
#pragma mark 土司
- (void)showToastWithString:(NSString *)msg
{
UILabel *label = [[UILabel alloc] init];
label.text = msg;
label.font = [UIFont systemFontOfSize:18];
label.textAlignment = NSTextAlignmentCenter;//内容居中
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor blackColor];
label.frame = CGRectMake(0, 0, screenWidth*0.8, screenHeight*0.07);//前面两个参数可以随便写,因为用center属性可以更快改变空间的中心坐标
label.center = CGPointMake(screenWidth/2, screenHeight*0.85);//此时label由于它自身的中心位置坐标发生了改变,所以上面一行代码中的0,0坐标就改变了
label.alpha = 0.0;//这里讲透明度设置为完全透明,是为了让它在之后渐渐显示出来。
//设置圆角
label.layer.cornerRadius = 10; //本行代码在IOS6中就可以给label设置圆角,但是在IOS7中不行,还需要再加上下面一行代码
label.layer.masksToBounds = YES;//默认是NO,超出主层边界的内容统统剪掉
[self.view addSubview:label];
//动画
[UIView animateWithDuration:1.0 animations:^{
label.alpha = 0.5;
} completion:^(BOOL finished)
{
[UIView animateWithDuration:1.0 delay:1.5 options:UIViewAnimationOptionCurveLinear animations:^{
label.alpha = 0.0;
} completion:^(BOOL finished)
{
[label removeFromSuperview];//将label从控制器中移除【也从内存中释放了】
}];
}];
}
//延迟执行, 延时执行 【3秒后被执行】
[self performSelector:@selector(delayFunction) withObject:self afterDelay:3.0f];
- (void)delayFunction
{
//...
}
//单例
+ (VideoChatVC *)getSelfIsSingleObj
{
static VideoChatVC *sharedAccountManagerInstance = nil;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
sharedAccountManagerInstance = [[VideoChatVC alloc] init];
});
return sharedAccountManagerInstance;
}
//本地推送
- (void)createNSNotification
{
//在yyy.m中
//推送 发送至 xxx.m
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"value", @"key", nil];
NSNotification *notification = [NSNotification notificationWithName:@"notification_someFun" object:nil userInfo:dic];
[[NSNotificationCenter defaultCenter] postNotification:notification];
//在xxx.m中
//接收 来此yyy类中发送的推送
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showWaitAlert:) name:@"notification_someFun" object:nil];
//接收推送时触发的函数
- (void)showWaitAlert:(NSNotification*)notify
{
NSString *value = notify.userInfo[@"key"];
}
//在dealloc中删除推送
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"notification_someFun" object:nil];
}
}
//远程推送
- (void)remotePush
{
{"aps":
{
"alert":"大老板要和你视频!!!", //弹出框
"badge":0, //徽章
"sound": "default", //提示音
"type":"voiceCalling",
"remoteID":"20702",
"roomID":"20702",
"receiveRequest":"custate"
}
}
}
//弹出框alert
- (void)showAlertKenshin
{
NSString *contentStr = @"对方长时间未接听,是否拨打对方普通电话?";
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:contentStr preferredStyle:UIAlertControllerStyleAlert];
if (alertController != nil)//这里的对话框 执行事件的时候会崩溃[iPhone4] 直接原因时 alertController == nil
{
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
{
}];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
{
NSLog(@"显示对方号码到拨号界面");
}];
[alertController addAction:cancelAction];
[alertController addAction:otherAction];
[self presentViewController:alertController animated:YES completion:nil];
}
else//iPhone4不支持UIAlertController?
{
//由- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex触发
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
message:contentStr
delegate:self
cancelButtonTitle:@"否"
otherButtonTitles:@"是",
nil];
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)//确定
{
NSLog(@"显示对方号码到拨号界面");
}
}
//隐藏状态栏
- (void)hiddenStaturBar
{
// 1. 如果只是想把当前页面的状态栏隐藏的话,直接用下面的代码就可以了
[[UIApplication sharedApplication] setStatusBarHidden:true];
// 2. 如果是想把整个应用程序的状态栏都隐藏掉,操作如下:
// 在info.plist上添加一项:Status bar is initially hidden,value为YES;
// 完后在MainAppDelegate.mm的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法里面加上如下一句就可以了:
// [[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
}
//获取当前手机型号
+ (NSString *)getCurrentDeviceModel
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G (A1203)";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G (A1241/A1324)";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS (A1303/A1325)";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (A1332)";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4 (A1332)";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (A1349)";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S (A1387/A1431)";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (A1428)";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (A1429/A1442)";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c (A1456/A1532)";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c (A1507/A1516/A1526/A1529)";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s (A1453/A1533)";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s (A1457/A1518/A1528/A1530)";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus (A1522/A1524)";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6 (A1549/A1586)";
if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s Plus (A1522/A1524)";
if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s (A1549/A1586)";
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G (A1213)";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G (A1288)";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G (A1318)";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G (A1367)";
if ([platform isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G (A1421/A1509)";
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad 1G (A1219/A1337)";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (A1395)";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (A1396)";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (A1397)";
if ([platform isEqualToString:@"iPad2,4"]) return @"iPad 2 (A1395+New Chip)";
if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini 1G (A1432)";
if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini 1G (A1454)";
if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini 1G (A1455)";
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3 (A1416)";
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad 3 (A1403)";
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad 3 (A1430)";
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad 4 (A1458)";
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad 4 (A1459)";
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad 4 (A1460)";
if ([platform isEqualToString:@"iPad4,1"]) return @"iPad Air (A1474)";
if ([platform isEqualToString:@"iPad4,2"]) return @"iPad Air (A1475)";
if ([platform isEqualToString:@"iPad4,3"]) return @"iPad Air (A1476)";
if ([platform isEqualToString:@"iPad4,4"]) return @"iPad Mini 2G (A1489)";
if ([platform isEqualToString:@"iPad4,5"]) return @"iPad Mini 2G (A1490)";
if ([platform isEqualToString:@"iPad4,6"]) return @"iPad Mini 2G (A1491)";
if ([platform isEqualToString:@"i386"]) return @"iPhone Simulator";
if ([platform isEqualToString:@"x86_64"]) return @"iPhone Simulator";
return platform;
}
@end