
1、开发者账号里面的id,需要勾选WiFi
2、权限文件需要添加Access WiFi Information为true
3、开启定位信息
4、获取WiFi信息
附注:
具体的Demo: >
QRcodeViewController qrViewC = [[QRcodeViewController alloc] init];
UINavigationController nav = [[UINavigationController alloc] initWithRootViewController:qrViewC];
[strongSelfpresentViewController:nav animated:YES completion:nil];
qrViewCresultQR= ^(NSStringinfo){
[strongSelfdismissViewControllerAnimated:YES completion:^{
NSStringresult;
NSMutableArrayresultArray = [NSMutableArrayarray];
BOOLtopChinese = [MultiRolesTopChinese:info];
if(topChinese){
NSArray array = [infocomponentsSeparatedByString:@"\r\n"];
resultArray = [NSMutableArrayarrayWithArray:array];
}else{
NSArray array = [infocomponentsSeparatedByString:@"\r\n"];
for(inta=0;a
// NSData data=[result dataUsingEncoding:NSUTF8StringEncoding];
NSDatadata=[array[a]dataUsingEncoding:NSShiftJISStringEncoding];
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSStringretStr = [[NSStringalloc]initWithData:dataencoding:enc];//如果中⽂文是utf-8编码转gbk结果为空
if([retStrisEqualToString:@""])//如果扫描中⽂文乱码则需要处理,否则不处理
{
NSIntegermax = [array[a]length];
charnbytes =malloc(max +1);
for(inti =0; i < max; i++)
{
unicharch = [array[a]characterAtIndex: i];
nbytes[i] = (char) ch;
}
nbytes[max] ='\0';
result=[NSStringstringWithCString: nbytesencoding: enc];
}else{
result = retStr;
}
[resultArrayaddObject:result];
}
}
因为初学iOS开发,对于layoutSubviews、drawRect等方法何时调用并不是了解得很透彻
所以在此记录一下,每当有新的发现都会在此更新,相信假以时日
这篇记录文能够产生丰富的内容以供我日后开发时的参考
本文章不设大小标题,仅以序号作为排版
iOS layout机制相关方法
- (CGSize)sizeThatFits:(CGSize)size
- (void)sizeToFit
——————-
- (void)layoutSubviews
- (void)layoutIfNeeded
- (void)setNeedsLayout
——————–
- (void)setNeedsDisplay
- (void)drawRect
--------------------
layoutSubviews在以下情况下会被调用:
1、init初始化不会触发layoutSubviews
但是是用initWithFrame 进行初始化时,当rect的值不为CGRectZero时,也会触发
2、当使用[self setNeedsDisplay]时会调用drawRect
3、当使用[self addSubview]会触发layoutSubviews
4、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
5、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件
6、滚动一个UIScrollView会触发layoutSubviews
7、旋转Screen会触发父UIView上的layoutSubviews事件
刷新子对象布局
-layoutSubviews方法:这个方法,默认没有做任何事情,需要子类进行重写
-setNeedsLayout方法: 标记为需要重新布局,异步调用layoutIfNeeded刷新布局,不立即刷新,但layoutSubviews一定会被调用
-layoutIfNeeded方法:如果,有需要刷新的标记,立即调用layoutSubviews进行布局(如果没有标记,不会调用layoutSubviews)
如果要立即刷新,要先调用[view setNeedsLayout],把标记设为需要布局,然后马上调用[view layoutIfNeeded],实现布局
在视图第一次显示之前,标记总是“需要刷新”的,可以直接调用[view layoutIfNeeded]
---------------------------------------
重绘
-drawRect:(CGRect)rect方法:重写此方法,执行重绘任务
-setNeedsDisplay方法:标记为需要重绘,异步调用drawRect
-setNeedsDisplayInRect:(CGRect)invalidRect方法:标记为需要局部重绘
sizeToFit会自动调用sizeThatFits方法;
sizeToFit不应该在子类中被重写,应该重写sizeThatFits
sizeThatFits传入的参数是receiver当前的size,返回一个适合的size
sizeToFit可以被手动直接调用
sizeToFit和sizeThatFits方法都没有递归,对subviews也不负责,只负责自己
----------------------------------------
layoutSubviews对subviews重新布局
layoutSubviews方法调用先于drawRect
setNeedsLayout在receiver标上一个需要被重新布局的标记,在系统runloop的下一个周期自动调用layoutSubviews
layoutIfNeeded方法如其名,UIKit会判断该receiver是否需要layout根据Apple官方文档,layoutIfNeeded方法应该是这样的
layoutIfNeeded遍历的不是superview链,应该是subviews链
drawRect是对receiver的重绘,能获得context
setNeedDisplay在receiver标上一个需要被重新绘图的标记,在下一个draw周期自动重绘,iphone device的刷新频率是60hz,也就是1/60秒后重绘
添加了新的类 UIAlertController 和 UIAlertAction 来取代曾经的 UIAlertView 和 UIActionSheet,感觉警告窗口的结构更容易理解了,使用起来也更简便。但是曾经用 Xcode 5 创建过 iOS 7程序在iOS 8 设备上运行就会出现各种问题。我清晰地记得刚刚升级 iOS 8 后连微信的警示 *** 作表也出了问题,猜测可能是因此而起的。
下面来看看UIAlertController 和 UIAlertAction 用法:
1 最简单的提醒视图:
这里我们实现一个最简单的提醒视图,包含1个标题,1行信息,1个按键,按下按键后,什么都不发生:
[objc] view plain copy
- (IBAction)doAlert:(id)sender {
// 准备初始化配置参数
NSString title = @"Alert Button Selected";
NSString message = @"I need your attention NOW!";
NSString okButtonTitle = @"OK";
// 初始化
UIAlertController alertDialog = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
// 创建 *** 作
UIAlertAction okAction = [UIAlertAction actionWithTitle:okButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction action) {
// *** 作具体内容
// Nothing to do
}];
// 添加 *** 作
[alertDialog addAction:okAction];
// 呈现警告视图
[self presentViewController:alertDialog animated:YES completion:nil];
}
进入程序后,点击“Alert Me!”按钮可触发这个提醒框,如图所示:
从代码可以看出,新的API更加符合逻辑,有种需要什么就加什么的感觉。
2 多个按键的提醒视图
这里我们实现一个最简单的提醒视图,包含1个标题,1行信息,3个按键,按下按键后,标签显示按下的按键名称:
[objc] view plain copy
- (IBAction)doMultiButtonAlert:(id)sender {
// 准备初始化配置参数
NSString title = @"Alert Button Selected";
NSString message = @"I need your attention NOW!";
NSString okButtonTitle = @"OK";
NSString neverButtonTitle = @"Never";
NSString laterButtonTitle = @"Maybe Later";
// 初始化
UIAlertController alertDialog = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
// 分别3个创建 *** 作
UIAlertAction laterAction = [UIAlertAction actionWithTitle:laterButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction action) {
// 普通按键
selfuserOutputtext = @"Clicked 'Maybe Later'";
}];
UIAlertAction neverAction = [UIAlertAction actionWithTitle:neverButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction action) {
// 红色按键
selfuserOutputtext = @"Clicked 'Never'";
}];
UIAlertAction okAction = [UIAlertAction actionWithTitle:okButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction action) {
// 取消按键
selfuserOutputtext = @"Clicked 'OK'";
}];
// 添加 *** 作(顺序就是呈现的上下顺序)
[alertDialog addAction:laterAction];
[alertDialog addAction:neverAction];
[alertDialog addAction:okAction];
// 呈现警告视图
[self presentViewController:alertDialog animated:YES completion:nil];
}
3个按键分别代表了3种不同类型的按键,分别是默认按键(普通)、销毁按键(红色)和取消按键(粗体)。从代码看其实就是在上一个的基础上加了3个 UIAlertAction 而已,然后分别设置不同的 style,效果如下:
3 带输入框的提醒视图
如何添加输入框呢?新的 iOS 8 提供了相应的接口,使增加输入框就像增加按键方法一样简单。这里还是在第1个方法的基础上改动。
[objc] view plain copy
- (IBAction)doAlertInput:(id)sender {
// 准备初始化配置参数
NSString title = @"Email Address";
NSString message = @"Please enter your your email address:";
NSString okButtonTitle = @"OK";
// 初始化
UIAlertController alertDialog = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
// 创建文本框
[alertDialog addTextFieldWithConfigurationHandler:^(UITextField textField){
textFieldplaceholder = @"Your Email";
textFieldsecureTextEntry = NO;
}];
// 创建 *** 作
UIAlertAction okAction = [UIAlertAction actionWithTitle:okButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction action) {
// 读取文本框的值显示出来
UITextField userEmail = alertDialogtextFieldsfirstObject;
selfuserOutputtext = userEmailtext;
}];
// 添加 *** 作(顺序就是呈现的上下顺序)
[alertDialog addAction:okAction];
// 呈现警告视图
[self presentViewController:alertDialog animated:YES completion:nil];
}
在创建 *** 作前先创建文本框,以便后面的按键可以 *** 作文本框内容。创建文本框也只是用了一个简单的方法而已,想创建更多文本框就再使用多次这个方法即可,程序效果如下:
4 提醒图表
与第2个和第3个方法相比,创建提醒图表简直易如反掌。因为和第1个方法相比,只需要改动一个参数就可以,即把创建UIAlertController实例的参数 UIAlertControllerStyleAlert 改为 UIAlertControllerStyleActionSheet ,别的都不用变。
[objc] view plain copy
- (IBAction)doActionSheet:(id)sender {
// 准备初始化配置参数
NSString title = @"Alert Button Selected";
NSString message = @"I need your attention NOW!";
NSString okButtonTitle = @"OK";
NSString neverButtonTitle = @"Never";
NSString laterButtonTitle = @"Maybe Later";
// 初始化
UIAlertController alertDialog = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
// 分别3个创建 *** 作
UIAlertAction laterAction = [UIAlertAction actionWithTitle:laterButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction action) {
// 普通按键
selfuserOutputtext = @"Clicked 'Maybe Later'";
}];
UIAlertAction neverAction = [UIAlertAction actionWithTitle:neverButtonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction action) {
// 红色按键
selfuserOutputtext = @"Clicked 'Never'";
}];
UIAlertAction okAction = [UIAlertAction actionWithTitle:okButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction action) {
// 取消按键
selfuserOutputtext = @"Clicked 'OK'";
}];
// 添加 *** 作(顺序就是呈现的上下顺序)
[alertDialog addAction:laterAction];
[alertDialog addAction:neverAction];
[alertDialog addAction:okAction];
// 呈现警告视图
[self presentViewController:alertDialog animated:YES completion:nil];
}
这个就很简单了,跟第2个方法很像,效果如图:
5 播放系统声音、提醒声音和振动设备
在 iOS 8 中,调用声音的方法发生了小变化,用曾经的方式无法获取系统声音文件的 soundID 。因此,这里直接调用 soundID 值来调用对应的声音,注意振动仍然正常调用kSystemSoundID_Vibrate常量即可:
[objc] view plain copy
- (IBAction)doSound:(id)sender {
// 播放系统声音
AudioServicesPlaySystemSound(1005);
}
- (IBAction)doAlertSound:(id)sender {
// 播放提醒声音
AudioServicesPlayAlertSound(1006);
}
- (IBAction)doVibration:(id)sender {
// 执行震动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
这样在 iOS 8 中就可以对用户发出提示了。
以上就是关于iOS swift 获取设备连接的WiFi的信息全部的内容,包括:iOS swift 获取设备连接的WiFi的信息、iOS app中获取git信息、iOS 使用QRcode扫码获取信息并解码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)