iOS应用内置AppStore以及iOS Safar…

来源:互联网 发布:算法工程师学什么专业 编辑:程序博客网 时间:2024/06/04 01:11
今天才发现在iOS6中,可以不跳转到AppStore那个应用,可以在当前应用中进行推广。
本地Document地址:
file:///Users/shjborage/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/index.html#documentation/StoreKit/Reference/SKITunesProductViewController_Ref/Introduction/Introduction.html#//apple_ref/doc/constant_group/Product_Dictionary_Keys

使用这个组件(SKStoreProductViewController),API相当简单。就像发短信的组件类似,可以传个ID过去,就可以在应用中使用AppStore了,不用再跳转过去。

具体如下:

SKStoreProductViewController Class Reference

Inheritsfrom
UIViewController UIResponder NSObject
Conformsto
NSCoding(UIViewController)
UIAppearanceContainer(UIViewController)
NSObject(NSObject)
Framework
/System/Library/Frameworks/StoreKit.framework
Availability
Available in iOS 6.0 and later.
Companionguide
In-App PurchaseProgramming Guide
Declaredin
SKStoreProductViewController.h

Overview

SKStoreProductViewController objectpresents a store that allows the user to purchase other media fromthe App Store. For example, your app might display the store toallow the user to purchase another app.

To display astore, create a new SKStoreProductViewController objectand set its delegate. Then, present the view controller modallyfrom another view controller in your app. Your delegate dismissesthe view controller when the user completes the purchase.

To choose aspecific product, call the loadProductWithParameters:completionBlock: method,passing the iTunes item identifier for the item you want tosell.

Tasks

Setting a Delegate

  •   delegate  property

Loading a New Product Screen

  • – loadProductWithParameters:completionBlock:
  • Properties

    delegate

    The store viewcontroller’s delegate.

    @property(nonatomic, assign) id<SKStoreProductViewControllerDelegate>delegate
    Discussion

    Your application must set the delegate before presenting the storeview controller.

    Availability
    • Available in iOS 6.0 andlater.
    Declared In
    SKStoreProductViewController.h

    Instance Methods

    loadProductWithParameters:completionBlock:

    Loads a new product screen to display.

    - (void)loadProductWithParameters:(NSDictionary *)parameters completionBlock:(void(^)(BOOL result, NSError *error))block
    Parameters
    parameters

    A dictionary describing the content you want the view controller todisplay. See “ProductDictionary Keys.”

    block

    A block to be called when the product information has been loadedfrom the App Store. The completion block is called on the mainthread and receives the following parameters:

    result

    YES if the product information wassuccessfully loaded, otherwise NO.

    error

    If an error occurred, this object describes the error. If theproduct information was successfully loaded, this valueis nil.

    Discussion

    In most cases, you should load the product information and thenpresent the view controller. However, if you load new productinformation while the view controller is presented, the contents ofthe view controller are replaced after the new product data isloaded.

    Availability
    • Available in iOS 6.0 andlater.
    Declared In
    SKStoreProductViewController.h

    Constants

    Product Dictionary Keys

    Keys supported inthe product dictionary.

    NSString * const SKStoreProductParameterITunesItemIdentifier;
    Constants
    SKStoreProductParameterITunesItemIdentifier

    The valueassociated with this key should be a string representing the iTunesidentifier for the item you want the store to display when the viewcontroller is presented.

    Available iniOS 6.0 and later.

    Declaredin SKStoreProductViewController.h.

    Next



另外也可以在自己的网站中,使用
具体如下就是,在Html中写Meta即可,但仅支持iOS系统,而且不能内置在应用内部。

本地Document地址:file:///Users/shjborage/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS6.0.iOSLibrary.docset/Contents/Resources/Documents/index.html#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html

Promoting Apps with Smart App Banners

Safari has a new Smart App Banner feature in iOS 6 and later thatprovides a standardized method of promoting apps on the App Storefrom a website, as shown in Figure7-1.

Figure7-1  A Smart App Bannerof the Apple Store app

 

Note: Smart App Banners only showon iOS, not OS X.

 

Smart App Banners vastly improve users’ browsing experiencecompared to other promotional methods. As banners are implementedin iOS 6, they will provide a consistent look and feel across theweb that users will come to recognize. Users will trust thattapping the banner will take them to the App Store and not athird-party advertisement. They will appreciate that banners arepresented unobtrusively at the top of a webpage, instead of as afull-screen ad interrupting the web content. And with a large andprominent close button, a banner is easy for users to dismiss.

If the app is already installed on a user's device, the bannerintelligently changes its action, and tapping the banner willsimply open the app. If the user doesn’t have your app on hisdevice, tapping on the banner will take him to the app’s entry inthe App Store. When he returns to your website, a progress barappears in the banner, indicating how much longer the download willtake to complete. When the app finishes downloading, the Viewbutton changes to an Open button, and tapping the banner will openthe app while preserving the user’s context from your website.

Smart App Banners automatically determine whether the app issupported on the user’s device. If the device loading the bannerdoes not support your app, or if your app is not available in theuser's location, the banner will not display.

Implementing a Smart App Banner on Your Website

To add a SmartApp Banner to your website, include thefollowing meta tagin the head of each page where you’d like the banner to appear:

<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">

You can includethree comma-separated parameters inthe content attribute:

  • app-id: (Required.) Your app's unique identifier. To findyour app ID from the iTunes Link Maker, typethe name of your app in the Search field, and select theappropriate country and media type. In the results, find your appand select iPhone App Link in the column on the right. Your app IDis the nine-digit number in between id and ?mt.

  • affiliate-data: (Optional.) Your iTunes affiliate string,if you are an iTunes affiliate. If you are not, find out more aboutbecoming an iTunes affiliate at http://www.apple.com/itunes/affiliates/.

  • app-argument: (Optional.) A URL that provides context toyour native app. If you include this, and the user has your appinstalled, she can jump from your website to the correspondingposition in your iOS app. Typically, it is beneficial to retainnavigational context because:

    • Ifthe user is deep within the navigational hierarchy of your website,you can pass the document’s entire URL, and then parse it in yourapp to reroute her to the correct location in your app.

    • Ifthe user performs a search on your website, you can pass the querystring so that she can seamlessly continue the search in your appwithout having to retype her query.

    • Ifthe user is in the midst of creating content, you can pass thesession ID to download the web session state in your app so she cannondestructively resume her work.

    Youcan generatethe app-argument of eachpage dynamically with a server-side script. You can format ithowever you'd like, as long as it is a valid URL.

Note: You cannot display SmartApp Banners inside of a frame.

 

Providing Navigational Context to Your App

In your app,implement the application:openURL:sourceApplication:annotation: methodin your app delegate, which fires when your app is launched from aURL. Then provide logic that can interpret the URL that you pass.The value you set tothe app-argumentparameter is available asthe NSURL url object.

The examplein Listing7-1 illustrates a website that passesdata to a native iOS app. To accomplish this, detect if the URLcontains the string/profile.If it does, then open the profile view controller and pass theprofile ID number that is in the query string.

Listing7-1  Routing the user tothe correct view controller

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    // in this example, the URL from which the user came is http://example.com/profile/?12345
    // determine if the user was viewing a profile
    if ([[url path] isEqualToString:@"/profile"]) {
        // switch to profile view controller
        [self.tabBarController setSelectedViewController:profileViewController];
        // pull the profile id number found in the query string
        NSString *profileID = [url query];
        // pass profileID to profile view controller
        [profileViewController loadProfile:profileID];
    }
    return YES;
}
0 0
原创粉丝点击