iOS 7 之Airdrop 分享 URLs ,Media and Documents

Sharing URLs 


Open URLViewController.m and modify the implementation as shown below: 

- (void)loadURL:(NSURL *)URL{

self.objectsToShare = @[URL];

... the rest of the code ...

}

- (BOOL)webView:(UIWebView *)webViewshouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType{

if (navigationType == UIWebViewNavigationTypeLinkClicked){

self.textField.text = request.URL.absoluteString;

self.objectsToShare = @[request.URL];}

return YES;} 


The above code is similar to the previous implementation, but this time you’re usingan NSURL in objectsToShare; in this case since you are passing a web URL,AirDrop will launch Safari on the receiving device. 


Sharing media and documents 


Open ImageViewController.m and replace the implementation ofimagePickerController:didFinishPickingMediaWithInfo: with the following: 


- (void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
{

// What did user pick? Is it a movie or is it an image?

NSString *mediaType = info[UIImagePickerControllerMediaType];

// If it is an image...

if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){

// Update UI and the object to share.

self.imageView.image =info[UIImagePickerControllerOriginalImage];

self.objectsToShare =@[info[UIImagePickerControllerOriginalImage]];

}

// else, if it is a movie...

else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]){

// Get the URL to the movie for sharing

NSURL *assetURL = info[UIImagePickerControllerMediaURL];self.objectsToShare = @[assetURL];

// Update UI by taking a snapshot of the movie.

self.imageView.image = [selfsnapshotFromMovieAtURL:assetURL];

}

// Dismiss the picker.

[picker dismissViewControllerAnimated:YES completion:nil];} 


When the standard image picker returns — either from the camera or the photolibrary — the code then callsimagePickerController:didFinishPickingMediaWithInfo: with the media assetinformation. 


机制

For an image, the UIImagePickerControllerOriginalImage key leads to aUIImage object. An image preview is displayed on screen, and the image itself isadded to objectsToShare


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值