IOS app sharing Extensions

Source: Internet
Author: User
Tags list of attributes

There are a few common ways that you might want to share content across apps on the iOS platform:
The first is to realize the sharing of documents and data between apps of different devices through airdrop;
The second is to define a URL scheme for each app that accesses an app directly by accessing a URL that specifies a URL scheme;
The third is to send data, share data, and manipulate data between apps through Uidocumentinteractioncontroller or Uiactivityviewcontroller, which are packaged in two iOS SDKs;
The fourth is to use the app Extension, the extension of the iOS 8 SDK to provide the new features to achieve cross-app data manipulation and sharing;
There is also an integrated third-party SDK implementation of the limited app data sharing, such as social platform (QQ, Sina Weibo, etc.) to provide us with the official SDK, or integration of multiple social platform SHARESDK components and Friends Alliance share components.
For the integration of the use of the third-party SDK, the major platform official website has detailed documentation, and recommended two Apple Developer Center documentation: Inter-app Communication and document Interaction programming Topics for Ios. One of the previous written about how to make our app support sharing through UTI.

Principle
I explained in detail the UTI (Uniform type Identifier) in the article "detailing the UTI (uniform type identifier) provided by Apple", a set of apples that provided us with a specification for identifying entity content types in cocoa and cocoa touch applications , and the technology for implementing content correlation is based on this set of specifications. In iOS and Mac OS development, Apple has provided us with an interface for registering document types, which are global in type and can be detected by all applications and services in the system. So we can use the underlying detection to preview documents that are not supported in our app using other optional third-party apps, and we can also open and process documents from third-party apps in our app via this interface.

If our app can handle certain types of entity content, then we can register in the Info.plist file in our project. for which type and UTI to use, refer to my explanation in the article "explaining the UTI (uniform type identifier) provided by Apple". When a third-party app checks to see which apps can handle the content type specified by Apple's underlying detection technology, if our app is already registered for this type, then our app icon will appear in it and be a portal to our own app.

Main technology
The techniques used primarily for this underlying detection are the Uidocumentinteractioncontroller, Uiactivityviewcontroller, and quick look frameworks that are available in the iOS SDK. In addition, in iOS 8, Apple has provided developers with app Extension, a much larger way of sharing content between apps. For details on Uidocumentinteractioncontroller, Uiactivityviewcontroller, Quick look frames, and app extension, I plan to explain them in detail later in this article. In this article, we mainly talk about how to register the types of documents available in our app and simply use our app to process content shared by third-party apps.

Registering Available types
We need to add a new attribute cfbundledocumenttypes in the Info.plist file (actually entering "document types"), which is an array-type property, meaning that we can register multiple types at the same time. For each element in the array, there are many properties that can be specified, with a detailed list of attributes we can find in the official documentation: Core Foundation keys--cfbundledocumenttypes. Here's a list of the properties we used to do iOS development:

Cfbundletypename ("Icon File Name")
String type, which specifies a type of alias, which is used to refer to the name of the type we specify, generally to maintain uniqueness, we use UTI to identify.
Cfbundletypeiconfiles
An array type that contains the file name of the specified PNG icon, which specifies a type of icon, and the icon has a specific size identification:
Device Sizes
IPad x pixels, x pixels
IPhone and IPod touch x pixels, x pixels (high resolution)
Lsitemcontenttypes ("Document Content Type UTIs")
Array type, containing the UTI string, specifying all of the recognized types of our application collection
Lshandlerrank ("Handler rank")
A string type that contains owner,default,alternate,none four optional values that specify the priority level for a certain type, while the Launcher Service arranges the order of displayed apps based on that priority. Priority levels from high to low are owner,alternate,default. None indicates that this type is not acceptable.
With these basic attributes in view, we need to specify these attributes when registering the app's available types, depending on the requirements of each project, and with different property values. Example as a reference:

Add document types in info
And when we add all the properties, start running our program, and then go back to our info interface and see that the document types has changed, which proves that we have successfully registered the type of app available.


Successful registration, running the program display results
Open a third-party app
We've registered the types of apps that our app can recognize in the steps above, and now we can open a third-party app that uses the Uidocumentinteractioncontroller or the quick look frame to display content, with the iphone On the QQ program for example.

In the registration steps above, the registered Lsitemcontenttypes contains only the public.image of this UTI. So we first from the QQ application of my file, open different types of files to compare, you can see my file list contains two types of files, one is a. jpg extension of the picture file, a. pdf extension of the document file.


List of my files
When I open a picture file for a preview, click on another app to open it and see our app icon in the app list. A brief introduction to this page, the first line is Apple after iOS 7 gives us a way to use airdrop to share content through icloud between iphone, ipad or ipod touch devices. The second line is a list of apps identified by the Document Type Association technology. The third line is a list of actions that are identified by the document Association technique, which represents operations that can be performed on the document, such as copying, printing, and so on.


Open picture, show Zsutitestdemo app icon
And if I open a PDF file, I can't see our app icon.

Open PDF file, can't see Zsutitestdemo app icon
Program Callback
When we successfully display the Zsutitestdemo icon after the above steps, click on the icon and we can jump to the Zsutitestdemo app, and Apple's method of receiving callbacks in the iOS SDK has changed after iOS 9. So 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: (NullableNSString*) sourceapplication Annotation: (ID) annotation{Uinavigationcontroller*navigation = (Uinavigationcontroller*) Application. Keywindow. Rootviewcontroller; Viewcontroller *displaycontroller = (Viewcontroller *) navigation. Topviewcontroller; [Displaycontroller. ImageViewsetimage:[UIImageImagewithdata:[nsdata Datawithcontentsofurl:url]]; [Displaycontroller. LabelSettext:sourceapplication];return YES;}#else- (BOOL) Application: (uiapplication*) Application OpenURL: (Nsurl*) URL options: (nonnullnsdictionary<NSString*,ID> *) options{Uinavigationcontroller*navigation = (Uinavigationcontroller*) Application. Keywindow. Rootviewcontroller; Viewcontroller *displaycontroller = (Viewcontroller *) navigation. Topviewcontroller; [Displaycontroller. ImageViewsetimage:[UIImageImagewithdata:[nsdata Datawithcontentsofurl:url]]; [Displaycontroller. LabelSettext:[options Objectforkey:uiapplicationopenurloptionssourceapplicationkey]];return YES;}#endif

IOS app sharing Extensions

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.