IOS9-by-Tutorials-Study Notes 3: Your-App-on-the-Web

Source: Internet
Author: User

IOS9-by-Tutorials-Study Notes 3: Your-App-on-the-Web
IOS9-by-Tutorials-Study Notes 3: Your-App-on-the-Web

I have not been able to perform experimental tests due to some restrictions in this article. I just try my best to explain some knowledge in the book and may make mistakes. I will be qualified later, I will experiment with the content in this article. But it is good to understand the content.

Before iOS 9, native and web on the iPhone were basically two independent parts. However, Apple is trying to narrow down the distance between the two and keep them closer and closer. After exiting universal links and web markup in iOS 9, you can provide deep links to directly access your app and search your content in Spotlight and Safari.

Getting started

This chapter provides two projects, one for the APP and the other for the Server, because the Server needs to modify some things. APP can be through address: https://itunes.apple.com/us/app/rwdevcon-tutorial-conference/id958625272? Mt = 8. The APP is as follows:

Linking to your app

Before getting started, let's review the predecessor of universal link: deep links. Through this review, you can find out some problems in deep links.

Deep links

Before iOS 9, we can set the URL scheme for the APP and add the CFBundleURLTypes key in Info. plist. The general format is similar ://. In addition, you should have seen Apple's own URL scheme, such as tel: // and sms.

Once URL scheme is set, the APP can be called by using the openURL (_ :) method. Some parameters can be included later in the call. Then, in our own program, we can perform corresponding processing in the application (_: handleOpenURL :) of AppDelegate. This system has existed for a long time, but some problems are exposed:
* Secure UIApplication has a canOpenURL (_ :) method that can be used to check whether a user can open a URL secheme. Apple's design is good, however, unfortunately, many developers now use this to detect what apps are arranged on users' mobile phones. This collects the user's APP list and involves the user's privacy.

CanOpenURL (_ :) is restricted in iOS9. to use this method, you must first add all the addresses to info. in plist, the APP installation cannot be detected by the server.

Because URL scheme is defined by each APP developer, it is likely that the two APP developers have the same definition. If openURL (_ :) is used, the iPhone will not know how to handle it. No fallback: If iOS tries to open a unregistered URL scheme, it will silent and fail, and the user does not know what happened.

IOS uses universal links to solve these problems. Use universal links instead of URL scheme. Universal links uses standard HTTP and HTTPS links.

Universal links

Here is an example: You have a domain name clownapp.com, you can register the http://clownapp.com as your universal link. If you have installed your clownapp. When he clicks links in Safari or web view. If you do not install fizbo, you will be directed to the profile page of fizbo on your website. If you use openURL (_ :) to open it, it will be the same as this action.

PS: here is an example of running a book. It cannot be opened in Safari of the simulator. It may be my reason.

Universal links and deep links have the following features:
* The unique domain name can guarantee the uniqueness.
* Securely bind your app to your domain name and upload a secure signature to your website server. Similarly, other apps will not easily know whether your APP is installed on your mobile phone.

The original text here is as follows: There's also no way for other apps to tell whether your app is installed. This is not no way, but it is not as easy as it is. The URL scheme whitelist can still be used for detection.

Simply because the connection to the APP and server is unified, you do not need to consider using two sets of different links on the APP and mobile phone. Register your App so that it can process the universal links

To enable the App to process the corresponding link, first let the App know what link to process. The link used here is rwdecon.com. Add the corresponding link as follows:

Here, you may select an Account. At this time, you can select your corresponding Account. If you do not have an Account, you can add it to the Account.

Registering your server can handle unilateral links

Under the root directory of the server, add a file named apple-app-site-association (without a suffix) and add the following content to it:

{    "applinks": {        "apps": [],        "details": [            {                "appID": "KFCNEC27GU.com.razeware.RWDevCon",                "paths": [                    "/videos/\*"                ]            }        ]    }}

The appId is composed of the team ID and bundle ID. The Paths array contains a URL whitelist that your App should process. This paths array also supports basic pattern matching, such *,? And so on, such as/videos/*/year/201? /VideoName.

This file needs to be uploaded to the root directory of the server and can be accessed over HTTPS without redirection.

Process universal links on your App

This part of the Code has not been tested

The corresponding universal links has been added above, and the corresponding link needs to be processed in the App below. Here we need to parse the corresponding link and then do some relevant business logic. Add the following method to Session. swift. This method is mainly used to parse the corresponding url:

class func sessionByWebPath(path: String,context: NSManagedObjectContext) -> Session? {  let fetch = NSFetchRequest(entityName: "Session")  fetch.predicate = NSPredicate(format: "webPath = %@", [path])  do {    let results = try context.executeFetchRequest(fetch)    return results.first as? Session  } catch let fetchError as NSError {    print("fetch error: \(fetchError.localizedDescription)")  }  return nil}

Add the following method in AppDelegate. swift:

Extension AppDelegate {// auxiliary method func presentVideoViewController (URL: NSURL) {let storyboard = UIStoryboard (name: "Main", bundle: nil) let navID = "NavPlayerViewController" let navVideoPlayerVC = storyboard. instantiateViewControllerWithIdentifier (navID)! UINavigationController navVideoPlayerVC. modalPresentationStyle =. FormSheet if let videoPlayerVC = navVideoPlayerVC. topViewController? AVPlayerViewController {videoPlayerVC. player = AVPlayer (URL: URL) let rootViewController = window ?. RootViewController ?. PresentViewController (navVideoPlayerVC, animated: true, completion: nil)} func application (application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void)-> Bool {// 1 The system uses NSUserActivityTypeBrowsingWeb to represent the corresponding universal HTTP links if userActivity. activityType = NSUserActivityTypeBrowsingWeb {let universalURL = userActivity. webpageURL! // 2 extract different parts of the url if let components = NSURLComponents (URL: universalURL, resolvingAgainstBaseURL: true), let path = components. path {if let session = Session. sessionByWebPath (path, context: coreDataStack. context) {// 3 find the session, and then play video let videoURL = NSURL (string: session. videoUrl )! PresentVideoViewController (videoURL) return true} else {// 4 can't understand open the Home Page let app = UIApplication. sharedApplication () let url = NSURL (string: "http://www.rwdevcon.com ")! App. openURL (url) }}return false }}

There are two links below. You can write an email with two links above and below. The first one is able to play the video normally, and the second one is to directly open the homepage of the website. PS: I did not test successfully

good linkhttp://www.rwdevcon.com/videos/talk-tammy-coron-possible.htmlbad linkhttp://www.rwdevcon.com/videos/tim-cook-keynote.html
Use web markup

Search contains three different APIs: NSUserActivity, CoreSpotlight, and web markup. The first two have already been introduced. Now let's look at the third one.

You can use web markup to get the content in your app in the search results. If you have a website with the same content as the APP, you can use the basic markup, Smart App Banners, and native App to process the universal links to modify your website, so that it can be searched and displayed better.

Apple has its own crawler. If your website uses web markup, Apple's crawler can collect the corresponding information and save it to its own server, other users can then search for the corresponding content, regardless of whether the user has installed your App. This will also help you obtain some users.

Make your website accessible

Apple crawlers crawl data everywhere, but they may not be able to quickly find your website. Here is a way to help Apple crawlers discover your website.
1. In iTunes ConnectSupport URLLocation, SetMarketing URL, Pointing to the website that you have used markup.

2. Make sure that the URL you entered can be accessed by Apple crawlers.
3. Check your robots.txt file to ensure that Apple crawlers can crawl your website normally. PS: It's about robots.txt Baidu.

Add Smart App Banners

After the Smart App Banners is added, a banner will appear on the top when you OPEN the website. for users who have already installed the App, an open button will be displayed to help users OPEN the corresponding App, for users who have not installed an App, A view button will appear. Clicking it will go to the App store to download the App. For example:

To achieve this, add the following code on the webpage where you want to add a banner:

  

Here, the name is the name of the App in the store. The following content contains two parts:
* App-id the app id on the store
* App-argument contains the URL to jump back to the App. Before iOS 9, this parameter is a custom URL scheme deep link. Now Apple recommends using HTTP/HTTPS universal links.

Smart App Banners only supports Safari

You can use the open mobile links supported by Applebot, such as Twitter Cards and App Links. However, I did not test the two tags myself, so I just pasted the Code:

// Twitter Cards specific https://dev.twitter.com/cards/mobile
// App Links specific http://applinks.org Semantic markup using Open Graph

The crawling of your content by Apple crawlers does not guarantee that it will be displayed in Spotlight's search results, because it will compete with other search results.

Apple hasn't published a specific rating algorithm, just to make sure your content is taken into consideration. When users click or search results are clearly highly correlated with your content, they will be prioritized by Apple.

Finally, Apple recommends adding some structured data for markup to better display it in Spotlight in Rich Text Format.

            

I have not found any source for the attributes behind the above og. If you have any idea, please leave a message to explain it. Thank you.

For more information about web markup, see the apple documentation https://developer.apple.com/library/ios/documentation/General/Conceptual/AppSearch/WebContent.html.

Finally, I have not conducted any tests due to some resource problems in this article. Maybe something is wrong. If anything is wrong, please point it out. Thank you.

It suddenly seems that this is the most basic 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.