iOS NFC
#import <CoreNFC/CoreNFC.h>
@interface ViewController ()<NFCNDEFReaderSessionDelegate>
@property (nonatomic,retain) UIButton *beginTestBtn;
@property (nonatomic,retain) UILabel *textLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_beginTestBtn = [[UIButton alloc]initWithFrame:CGRectMake(, , , )];
[_beginTestBtn setTitle:@"开始读取" forState:UIControlStateNormal];
[_beginTestBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
_beginTestBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
[_beginTestBtn addTarget:self action:@selector(beginTestBtnAction) forControlEvents:UIControlEventTouchUpInside];
_textLabel = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
_textLabel.text = @"待读取";
_textLabel.textColor = [UIColor orangeColor];
[self.view addSubview:_textLabel];
NSLog(@"进入VC");
[self.view addSubview:_beginTestBtn];
[self.view addSubview:_textLabel];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)beginTestBtnAction
{
/**
三个参数
第一个参数:代理对象
第二个参数:线程
第三个参数:Session读取一个还是多个NDEF。YES:读取一个结束,NO:读取多个
*/
NFCNDEFReaderSession *session = [[NFCNDEFReaderSession alloc] initWithDelegate:self queue:dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT) invalidateAfterFirstRead:YES];
[session beginSession];
}
/**
代理
*/
- (void) readerSession:(nonnull NFCNDEFReaderSession *)session didDetectNDEFs:(nonnull NSArray<NFCNDEFMessage *> *)messages {
__weak typeof(self) weakself=self;
dispatch_async(dispatch_get_main_queue(), ^{
weakself.textLabel.text = @"读取成功";
});
for (NFCNDEFMessage *message in messages) {
for (NFCNDEFPayload *payload in message.records) {
NSLog(@"Payload data:%@",payload.payload);
}
}
}
- (void)readerSession:(NFCNDEFReaderSession *)session didInvalidateWithError:(NSError *)error{
NSLog(@"error:%@",error);
__weak typeof(self) weakself=self;
dispatch_async(dispatch_get_main_queue(), ^{
weakself.textLabel.text = @"读取失败";
});
}
iOS NFC的更多相关文章
- Xamarin.Forms 简介
An Introduction to Xamarin.Forms 来源:http://developer.xamarin.com/guides/cross-platform/xamarin-forms ...
- 【转】http://www.cnblogs.com/yuzukwok/p/3884377.html
来自:http://www.cnblogs.com/yuzukwok/p/3884377.html An Introduction to Xamarin.Forms 来源:http://develop ...
- 【转】iOS开发 -- Apple Pay
技术博客原地址:http://www.cnblogs.com/dashunzi/p/ApplePay.html#top 原技术博客中有源码和视频,有感兴趣的朋友可以研究一下! 一.什么是Apple P ...
- NFC:Arduino、Android与PhoneGap近场通信
NFC:Arduino.Android与PhoneGap近场通信(第一本全面讲解NFC应用开发的技术著作移动智能设备近距离通信编程实战入门) [美]Tom Igoe(汤姆.伊戈),Don Colema ...
- iOS 7 与 Xamarin - MultiPeer Connectivity(转载)
随着时代的改变,移动设备在生活工作都开始取代原有的pc.设备间的数据交互就成为了必备可少的功能.比较成熟的产品有NFC.这个啪啪的操作很流行,例如分享图片,分享文件等 .但是在iOS设备中还没有NFC ...
- 【原】iOS学习39网络之数据请求
1. HTTP和HTTPS协议 1> URL URL全称是Uniform Resource Locator(统一资源定位符)通过1个URL,能找到互联网上唯一的1个资源 URL就是资源的地址.位 ...
- iOS开发 Apple Pay
一.什么是Apple Pay? 1. 概念 Apple Pay,简单来说, 就是一种移动支付方式.通过Touch ID/ Passcode,用户可使用存储在iPhone 6, 6p等设备上的信用卡和借 ...
- 配置jenkins,并把iOS包自动上传至fir.im
安装jenkins,有两种方式 1.首先要安装 homebrew,利用homebrew来管理安装包十分方便,一条命令就可以 安装 homebrew命令 $ ruby -e "$(curl - ...
- IOS开发UI基础之Plis文件-字典转模型
什么是plist文件? 在开发中直接将数据写在代码里面 不是一种合理的做法 如果数据经常改变 就需要经常翻开对应的代码进行修改 造成代码扩展性低 因此,可以考虑将经常变的数据放在⽂文件中进⾏行存储,程 ...
随机推荐
- Genymotion Android模拟器Genymotion的安装和使用
Android模拟器Genymotion的安装和使用 by:授客 QQ:1033553122 环境: Win7 Genymotion 2.12.0 下载地址:http://download.canad ...
- crontab常用
--crontab检查是否安装[oracle@rac1 ~]$ rpm -qa | grep crontabcrontabs-1.10-8启动与关闭[oracle@rac1 ~]$ /etc/init ...
- redis cluster + sentinel详细过程和错误处理三主三备三哨兵
redis cluster + sentinel详细过程和错误处理三主三备三哨兵1.基本架构192.168.70.215 7001 Master + sentinel 27001192.168.70. ...
- 向MIP开源项目提交Issues
Issues 是 GitHub 管理需求,讨论技术方案的方式,附:官方解释.MIP 是在 GitHub 上的开源项目,也使用 Issues 来做任务管理. 一.Issues 在 MIP 项目中的应用 ...
- Followme Devops实践之路
引言 天下武功,唯快不破 想要提高开发团队效率,势必要有一套完整而成熟的开发流程方案,除了sprint迭代开发模式之外,还有近几年流行的devops流程,都是可以大幅度提高开发效率的工具. 我们团队也 ...
- 将博客搬至CSDN https://blog.csdn.net/Fredric_2014
将博客搬至CSDN https://blog.csdn.net/Fredric_2014
- 事务,Oracle,MySQL及Spring事务隔离级别
一.什么是事务: 事务逻辑上的一组操作,组成这组操作的各个逻辑单元,要么一起成功,要么一起失败. 二.事务特性(4种): 原子性 (atomicity):强调事务的不可分割:一致性 (consiste ...
- Python基础(set集合)
#Author : Kelvin #Date : 2019/1/5 13:20 #set集合的创建(创建后可修改) li=["kelvin",1,2,"zhangsan& ...
- Linux性能评估工具
目录 介绍 负载:uptime 查看内核的信息: dmesg 查看内存状态: free.vmstat free: 查看内存,已用内存,剩余内存.交换分区等 vmstat:显示虚拟内存状况的信息. 查看 ...
- ASP.NET Core中使用GraphQL - 第三章 依赖注入
ASP.NET Core中使用GraphQL ASP.NET Core中使用GraphQL - 第一章 Hello World ASP.NET Core中使用GraphQL - 第二章 中间件 SOL ...