iOS 7 introduces a new easy to use way to share your data with nearby devicescalledAirDrop

用过mbp的都应该知道苹果有个比较好用的文件共享组件Airdrop 随着新系统的发布Airdrop也登陆了iPhone上 遗憾的是只有5和5S上又这个功能

关于Airdrop就不做过多的介绍了 类似蓝牙但是效率要比蓝牙高不少貌似

使用很简单苹果已经把方法写到了这个UIActivityViewController类里面

you can use to allowusers to easily share photos, documents, URLs, and other kinds of data from yourapp

在自己的APP中你可以通过Airdrop把照片、文件、链接等数据分享给其他的小伙伴

代码如下:

UIActivityViewController*controller =[[UIActivityViewControlleralloc]initWithActivityItems:objectsapplicationActivities:nil];

[selfpresentViewController:controlleranimated:YES completion:nil];

If the user chooses to send the data via AirDrop, once the other user receives thedata, it will be opened in an app based on the type of data:

•NSStringandNSAttributedStringappear as new notes inNotes.app.

•UIImageandAVAssetare presented inPhotos.app.

•NSURLis presented inSafari.app, unless it is a file URL, which will make the iOSto look for registered document types (UTI) and open the appropriate app.

It’s as simple as that when it comes to sending data. When it comes to receivingdata, it works the same way as it has in iOS in the past:

1.Register document types. You register your app to receive certain documenttypes of data.

2.User chooses app. When the user receives a document (whether via email, aweb link, AirDrop, etc.), the OS looks to see which app handles that type ofdocument and asks the user what app he/she wants to use to open the file.

3.Receive and process document. If the user chooses to open the document inyour app, you receive a URL to the data in an App Delegate callback.

The rest of this chapter walks you through how both send and receive data viaAirDrop in a practical example project, but if this is enough to get you started, feelfree to stop reading at this point and give it a shot in your app.

由于内容太多 先介绍分享任意数据的吧

iOS 7 Airdrop 允许用户分享任意数据类型的数据 只需要给他们一个 UTI(Uniform TypeIdentifier)就是数据类型标示符还必须得是唯一的

Registering UTIs

The interesting part of AirDrop is file sharing. You can share any data type — aslong as you turn it into a file first. For example, you can turn your custom objectsinto NSData, save them locally in a temporary folder with a custom Uniform TypeIdentifier (UTI), and then pass the file URL to AirDrop.

新建DocumentsViewController.m

代码如下:


  • -  (void)updateDocumentsToShareWithDocument:(NSURL*)document{

    ... insert at the end of the method implemetnation ...

    // Update object to share.

    self.objectsToShare= [self.toSharecopy];}

  • -  (void)updateViewWithNotification:(NSNotification*)notification{

    self.objectsToShare= nil;

    ... the rest of the code ...

    }

The Documents tab displays the list of files in app’s Documents directory that endwith .dm. User can select one or more files to send via AirDrop.

新建BaseViewController.h

/**
* @property objectsToShare
* @brief An array of objects that will be shared via AirDrop when

the activity view controller is presented.*/

@property (nonatomic, strong) NSArray *objectsToShare;

objectsToShare holds a list of things to share via AirDrop. Each subclass will fillthis with the appropriate set of objects.

// Create a UIBarButton item with UIBarButtonSystemItemAction anddisplay it in the navigation bar.
- (void)displayActionButton
{

UIBarButtonItem *actionButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemActiontarget:selfaction:@selector(actionButtonTapped:)];

[self.navigationItem setLeftBarButtonItem:actionButtonanimated:YES];

}

// Remove the action bar button item.

- (void)hideActionButton{

[self.navigationItem setLeftBarButtonItem:nil animated:YES];}

就不翻译了 自己看吧

displayActionButton and hideActionButton will be called when the list ofshareable objects changes. This pair of methods will initialize and display the actionbutton, or remove it from the navigation bar.

Next, add the following custom setter method:

- (void)setObjectsToShare:(NSArray *)objectsToShare{

_objectsToShare = [objectsToShare copy];

// If there is an object in the array to share, display the// action button; otherwise, hide the action button.
if ([objectsToShare count])

[self displayActionButton];else

}

[self hideActionButton];

In order to have more control over what is being shared, you’re providing a customsetter method for objectsToShare. The method will check the count of objects andhide or display the action button depending on whether there are any entries in thearray.

Next up is the workhorse method to invoke the share sheet dialog.Still working in BaseViewController.m, add the following method:

// Configure and present an instance of UIActivityViewControllerfor AirDrop only.
- (void)presentActivityViewControllerWithObjects:(NSArray*)objects

{

// 1 - Create an instance of UIActivityViewController with theobject.

UIActivityViewController *controller =[[UIActivityViewController alloc] initWithActivityItems:objectsapplicationActivities:nil];

// 2 - Exclude all activities except AirDrop.

NSArray *excludedActivities = @[UIActivityTypePostToTwitter,UIActivityTypePostToFacebook, UIActivityTypePostToWeibo,UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePrint,UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList,UIActivityTypePostToFlickr, UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo];

controller.excludedActivityTypes = excludedActivities;

// 3 - Present it.

[self presentViewController:controller animated:YEScompletion:nil];

}

1. Creates an instance of UIActivityViewController, passing in the array ofobjects.

2. Excludes all other possible options that UIActivityViewController can present— such as sharing via Twitter —since you want to limit the user to just AirDrop.

3. Displays UIActivityViewController as modal.
Finally, link the above method with the action button in the navigation bar by

adding this method:

- (IBAction)actionButtonTapped:(id)sender{

[selfpresentActivityViewControllerWithObjects:self.objectsToShare];}

When the action button is tapped, this method ties things together by callingpresentActivityViewControllerWithObjects:with the current list of objects toshare.

后面还会给大家介绍如何通过Airdrop分享图片、链接、媒体文件、文字等等。。。

iOS 7 之Airdrop 分享相关推荐

  1. 小龟视频APP-插件打包-v1.6.x反编译教程及未加固apk包ios最新版文件分享

    1.先爆破安卓签名,工具:MT管理器,百度自行下载 2.搜索getcertsign(一般在285之间都能看到)如下图: 3.添加return-void 然后保存返回回到首页进行APK签名,就ok了 这 ...

  2. iOS QQ空间 好友分享

    iOS QQ空间 好友分享 1.进入腾讯开发者平台,可以查看分享SDK文档,根据说明按步骤接入 demo演示 - (void)viewDidLoad { [super viewDidLoad]; // ...

  3. airdrop分享, Sender kSFOperationEventErrorOccured {

    使用 UIActivityViewController进行airdrop分享,代码如下: 方法一,使用URL,将要分享的文件的URL传入即可: NSURL *url = [NSURL fileURLW ...

  4. 微信公众号分享授权成功,IOS和安卓手机分享失败

    (1)IOS表现:可以分享到企业微信,但微信分享自定义卡片显示错误 原因分析: 图片太大 要分享的地址链接字符太长(避免链接带有太多参数)或者编码出现问题(特殊字符.汉字) (2)安卓手机分享不成功: ...

  5. iOS单独集成QQ分享功能

    2019独角兽企业重金招聘Python工程师标准>>> (1)首先,把TencentOpenAPI.framework.TencentOpenApi_IOS_Bundle.bundl ...

  6. ios 检测是否联网_秋招|阿里 iOS 五轮面经分享,已收到阿里的意向书

    作者:aaaaaazzzz 链接:https://www.nowcoder.com/discuss/302113 来源:牛客网 感觉牛客很少看到iOS的面经了,今天收到了阿里的意向书,来分享下面经,希 ...

  7. iOS网络层架构设计分享

    前言 前些天帮公司做了网络层的重构,当时就想做好了就分享给大家,后来接着做了新版本的需求,现在才有时间整理一下. 之前的网络层使用的是直接拖拽导入项目的方式导入了AF,然后还修改了大量的源码,时隔2年 ...

  8. ios使用友盟分享到QQ/微信时时如何判断手机上是否安装了QQ以及微信的客户端

    iOS 在使用友盟时,使用微信分享.登录必须安装微信客户端,QQ登录.QQ空间分享过程中必须安装手机QQ客户端,在未安装客户端的设备上测试会提示下载,这是不符合苹果审核规则的.这是微信及腾讯QQ互联导 ...

  9. iOS启动速度优化实践分享

    一款App的启动速度,不单单只有用户体验这一方面,往往还决定了它能否收获更多的用户.这就好像陌生人第一次碰面,第一感觉往往决定了他们接下来是否会继续交往.由此可见,启动速度的优化必然是App开发过程中 ...

  10. MacBook上如何运行那些尚未在Mac App Store 上架的 iOS/iPadOS 应用程序分享

    援引外媒 MacRumors 报道,论坛读者 Amy 反馈称在搭载 M1 芯片的 Mac 设备上可以运行任意 iOS 应用程序.随后外媒 The Verge 进行了实测,通过.ipa 文件的方式在 M ...

最新文章

  1. 使用钩子函数[4] - 钩子链和 CallNextHookEx 的返回值
  2. Spring3 MVC
  3. java 反射模式_java 设计模式——反射机制的应用
  4. 计算机主机配置有哪些,电脑主机配置清单有哪些 电脑主机配置清单及价格
  5. 约束最优化方法 (一) 最优性条件
  6. 关于移动开发的一些meta设置
  7. LabVIEW心率监测装置
  8. 可以用php做出一个圆锥吗,PS使用渐变工具画一个立体圆锥
  9. mac转换pin计算机,MAC对应PIN码表-2012.3.4整理
  10. mysql执行sql流程_mysql 执行sql流程
  11. 【软件入门】Typora快速入门
  12. 2k14无法打开因为计算机,NBA2K14虚拟光驱SCSI无法开启攻略_NBA2K14提示安装SPTD_快吧单机游戏...
  13. python中function takes exactly_Python 'takes exactly 1 argument (2 given)' Python error
  14. 例题9-27 方块消除 UVa10559
  15. alexnet 模型详解以及模型的可视化
  16. 技术博客一件发布系统的实验性技术方案Butterfly
  17. android 齐刘海编程,[翻译]Android适配全面屏上的齐刘海
  18. 【计算机毕业设计】36.网易购商城购物平台源码
  19. 渲染优化-从GPU的结构谈起
  20. 五金模具设计,端子模具设计要点

热门文章

  1. 解决:The APR based Apache Tomcat Native library which allows optimal performance in production......
  2. 图片:“给你五十行代码把我变成字符画!” 程序:“太多了,一半都用不完!”
  3. java osm_OSM初识(三)OSM Data
  4. 天气插件平台-天气预报插件-免费天气预报代码—中国天气网
  5. ME:环境DNA(eDNA)宏条形码技术正在转变我们考察动植物群落的方法
  6. Elasticsearch08:es-ik添加自定义词库、热更新词库
  7. ttf,eot,woff,svg,字体格式介绍及使用方法
  8. tangent space与object space
  9. 开源软件推荐-TMS运输管理系统 KYTMS
  10. Linux下的C编程(一)你好 世界