IOS app sharing Extension

Source: Internet
Author: User

IOS app sharing Extension

There are several common methods to share content between different apps on the iOS platform:
The first is to use AirDrop to share documents and data between apps of different devices;
The second type is to define a URL Scheme for each App. You can directly access an APP by specifying a URL of the URL Scheme;
The third is to send data, share data, and operate data between apps through the classes encapsulated in the two iOS sdks, UIDocumentInteractionController or UIActivityViewController;
The fourth is to use App Extension to implement cross-App data operations and sharing through the new Extension features provided in the iOS 8 SDK;
There is also an official SDK that integrates third-party sdks to share data with a limited number of apps, such as social platforms (QQ, Sina Weibo, etc, or ShareSDK components integrated with multiple social platforms and umeng sharing components.
For the use of integrated third-party sdks, the official websites of major platforms have detailed instructions. We also recommend two documents from the apple Developer Center: Inter-App Communication and Document Interaction Programming Topics for iOS. Previously, we wrote about how to share our App with the user through UTI.

Principle
In the article "ios uti (Uniform Type Identifier) opens an APP Based on the file suffix", I explained in detail the UTI (Uniform Type Identifier ), apple provides us with a set of specifications for identifying entity content types in Cocoa-based and Cocoa-based Touch applications, and the technology for implementing content associations is also based on this specification. In iOS and Mac OS development, Apple provides us with an interface for registering document types, which are globally registered, all applications and services in the system can be detected. Therefore, through this underlying detection, we can use other optional third-party apps to preview documents not supported in our apps, in addition, we can use this interface to open and process third-party App documents in our App.

If our App can process some types of entity content, we can register it in the Info. plist file of our project. For more information about which type and UTI are used, see the description in my article "explaining the UTI (unified type identifier) provided by Apple. When a third-party App uses Apple's underlying Detection Technology to check which apps can process the specified content type, if our App has already registered this type, then our App icon will be displayed in it and serve as an entry to our App.

Main technologies
This underlying detection technology is mainly applied to the UIDocumentInteractionController, UIActivityViewController, and Quick Look frameworks provided by the iOS SDK. In addition, in iOS 8, Apple provides App Extension for developers to share content between apps in a higher way. I plan to explain in detail the details of UIDocumentInteractionController, UIActivityViewController, Quick Look framework, and App Extension in the following articles. In this article, we mainly talk about how to register the available document types of our App and simply use our App to process the content shared by third-party apps.

Register available types
In info. in the plist file, add a new attribute CFBundleDocumentTypes (in fact, the input is "Document types"). This is an array type attribute, meaning that we can register multiple types at the same time. For each element in the array, many attributes can be specified. For the detailed attribute list, we can find the Core Foundation Keys -- CFBundleDocumentTypes in the official documentation. Here are the attributes that we often use in iOS development:

CFBundleTypeName ("Icon File Name ")
String type. It specifies an alias of a certain type, that is, it is used to indicate the alias of the specified type. Generally, to maintain uniqueness, we use UTI to identify it.
CFBundleTypeIconFiles
Array type, including the name of the specified png icon, which indicates a type of icon, and the icon has a specific size identifier:
Device Sizes
IPad 64x64 pixels, 320x320 pixels
IPhone and iPod touch 22x29 pixels, 44x58 pixels (high resolution)
LSItemContentTypes ("Document Content Type UTIs ")
Array type, including the UTI string, which specifies all types that can be recognized by our application.
LSHandlerRank ("Handler rank ")
String type, which contains four optional values: Owner, Default, Alternate, And None. This parameter specifies the priority level of a type, and the Launcher Service sorts the displayed App order based on this priority level. The priority levels are from high to low: Owner, Alternate, and Default. None indicates that this type is not accepted.
After learning about these basic attributes, We need to specify these attributes when registering the available App type. The attribute values vary depending on the needs of each project. Example as a reference:

Add Document types in info
After adding all the attributes, run our program and return to our Info interface. The list of Document types has changed, this proves that we have successfully registered the available types of the App.


The registration is successful. The result displayed by running the program
Open third-party applications
We have registered the types that our App can recognize in the above steps. Now we can open a third-party App that uses the UIDocumentInteractionController or Quick Look framework to display content, here, the QQ program on the iPhone is used as an example.

In the above registration procedure, the registered LSItemContentTypes only contains the public. image (UTI. .


My file list
When I open an image file for preview, click another application to open it. Then, we can see our App icon in the App list. The first line of this page is the AirDrZ release provided by Apple after iOS 7? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> character/character + character/yb340NC1xLLZ1/character + DQo8cD48aW1nIGFsdD0 =" here write picture description "src =" http://www.bkjia.com/uploads/allimg/160415/0419103921-3.png "title =" \ "/>
Open the image and display the ZSUTITestDemo App icon
If I open a PDF file, we will not be able to see our App icon.

Open the PDF file and you cannot see the ZSUTITestDemo App icon.
Program callback
After successfully displaying the ZSUTITestDemo icon, click the icon to go to The ZSUTITestDemo application, the method that Apple provided to us in iOS SDK for receiving callbacks has changed since iOS 9. Therefore, we need to make changes to different device versions:

#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation{ UINavigationController *navigation = (UINavigationController *)application.keyWindow.rootViewController; ViewController *displayController = (ViewController *)navigation.topViewController; [displayController.imageView setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:url]]]; [displayController.label setText:sourceApplication];return YES;}#else - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(nonnull NSDictionary
  
    *)options{UINavigationController *navigation = (UINavigationController *)application.keyWindow.rootViewController; ViewController *displayController = (ViewController *)navigation.topViewController; [displayController.imageView setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:url]]]; [displayController.label setText:[options objectForKey:UIApplicationOpenURLOptionsSourceApplicationKey]];return YES;}#endif
  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.