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.

3239

被折叠的 条评论
为什么被折叠?



