Use the SDK

更新时间:
复制 MD 格式

After you add the software development kit (SDK), complete the following steps to integrate real-time release into your iOS client:

  1. Check for new versions: Call the SDK interface method to check for new versions.

  2. Configure a phased release whitelist: Set options such as upgrade prompts and phased releases.

    Important

    If you remove the UTDID dependency, time-window phased releases will not work.

  3. Publish online: Generate an IPA file in the mPaaS console and publish the new version.

Procedure

Check for new versions

The upgrade check SDK provides interfaces for checking application updates. When a new version is detected, the SDK behaves as follows depending on your UI requirements:

  • If you use the default mPaaS pop-up, the SDK automatically displays an upgrade prompt.

  • If you use a customized mPaaS pop-up, the SDK calls your delegate methods to render a custom image, toast, or progress bar.

  • If you use a fully custom UI, the SDK returns upgrade information as a dictionary for you to handle.

The method header file is located in AliUpgradeCheckService.framework > Headers > MPCheckUpgradeInterface.h.

typedef NS_ENUM(NSUInteger, AliUpdateType) {
    AliUpgradeNewVersion = 201,            /*The current version is the latest.*/
    AliUpgradeOneTime,                     /*A new version is available on the client. Remind once.*/
    AliUpgradeForceUpdate,                 /*A new version is available on the client. Force upgrade (deprecated).*/
    AliUpgradeEveryTime,                   /*A new version is available on the client. Remind multiple times.*/
    AliUpgradeRejectLogin,                 /*Restrict logon (deprecated).*/
    AliUpgradeForceUpdateWithLogin         /*A new version is available on the client. Force upgrade.*/
};

/**
 Success callback for upgrade check when using a custom UI.

 @param upgradeInfos Upgrade information.
 @{upgradeType:202,
 downloadURL:@"itunes://downLoader.xxxcom/xxx",
 message:@"A new version is available. Please upgrade.",
 upgradeShortVersion:@"9.9.0",
 upgradeFullVersion:@"9.9.0.0000001"
 needClientNetType:@"4G,WIFI",
 userId:@"admin"
 }
 */
typedef void(^AliCheckUpgradeComplete)(NSDictionary *upgradeInfos);
typedef void(^AliCheckUpgradeFailure)(NSException *exception);

@interface MPCheckUpgradeInterface : NSObject

/**
 The time interval for a single reminder, in days. Default value: 3.
 */
@property(nonatomic, assign) NSTimeInterval defaultUpdateInterval;

/**
 The delegate for modifying the default pop-up UI.
 */
@property (nonatomic, weak) id<AliUpgradeViewDelegate> viewDelegate;

/**
 * Initializes the instance.
 */
+ (instancetype)sharedService;

/**
 Actively checks for updates. If an update is found, a pop-up window is automatically displayed using the default mPaaS UI.
 *
 */
- (void)checkNewVersion;

/**
 Actively checks for updates. A pop-up window is not automatically displayed. This is typically used for custom UIs, checking for updates, or displaying notification dots.

 @param complete Success callback. Returns a dictionary of upgrade information.
 @param failure  Failure callback.
 */
- (void)checkUpgradeWith:(AliCheckUpgradeComplete)complete
                 failure:(AliCheckUpgradeFailure)failure;
@end

Call the appropriate interface after the app starts. To avoid slowing down startup, call the interface after the home page appears. Three options are available:

  • Use the default mPaaS pop-up to display the upgrade prompt:

      - (void)checkUpgradeDefault {
          [[MPCheckUpgradeInterface sharedService] checkNewVersion];
      }
  • Customize the default mPaaS pop-up UI with a custom image, network notification toast, or progress bar for network requests:

      - (void)checkUpgradeWithHeaderImage {
          MPCheckUpgradeInterface *upgradeInterface = [MPCheckUpgradeInterface sharedService];
          upgradeInterface.viewDelegate = self;
          [upgradeInterface checkNewVersion];
      }
    
      - (UIImage *)upgradeImageViewHeader{
          return APCommonUILoadImage(@"ilustration_ap_expection_alert");
      }
    
      - (void)showToastViewWith:(NSString *)message duration:(NSTimeInterval)timeInterval {
          [self showAlert:message];
      }
    
      - (void)showAlert:(NSString*)message {
          AUNoticeDialog* alertView = [[AUNoticeDialog alloc] initWithTitle:@"Information" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
          [alertView show];
      }
  • Use a fully custom UI to retrieve upgrade information and handle the display yourself:

      - (void)checkUpgradeWIthCustomUI {
          [[MPCheckUpgradeInterface sharedService] checkUpgradeWith:^(NSDictionary *upgradeInfos) {
              [self showAlert:[upgradeInfos JSONString]];
          } failure:^(NSException *exception) {
          }];
      }

Configure a phased release whitelist

To use the phased release whitelist feature, the server must be able to identify each client. In the MPaaSInterface category, configure the userId method to return a unique identifier for the app, such as a username, phone number, or email address.

@implementation MPaaSInterface (Portal)

- (NSString *)userId
{
    return @"mPaaS";
}

@end

For information about configuring a whitelist in the mPaaS console, see Real-time Release > Whitelist Management.

Publish online

Generate an IPA file

  • Use Xcode to generate an IPA package:

  • Alternatively, use the mPaaS plugin packaging feature to generate an IPA package. The package is saved to the product directory of the current project. Configure the following fields:

    • Bundle Identifier: Must match the Bundle ID in the cloud configuration file.

    • Bundle Version: Must match the value of Production Version in the project's info.plist file.

    • Provisioning Profile: The signing configuration file. Must match the Bundle ID; otherwise, packaging fails.

    • Debug: Specifies whether to generate a debug package.

    • App Store: Specifies whether to generate a release package for the App Store.

Publish a new version

Use the release management feature to publish a new version. For more information, see Release Management.

Upgrade mode

When you create a release task in the mPaaS console, select an upgrade mode that controls how often users are prompted. After the first prompt, the SDK checks whether the cool-down period has elapsed before showing the prompt again, so users are not prompted more than once per period on subsequent upgrade check calls.

  • Single reminder: The client is prompted once per cool-down period, even if the upgrade check interface is called multiple times.

    • Use this mode to encourage upgrades without disrupting users.

    • The default cool-down period is 3 days. To change it, set the following property before calling the upgrade check interface:

        - (void)checkUpgradeDefault {
            [MPCheckUpgradeInterface sharedService].defaultUpdateInterval = 7;
            [[MPCheckUpgradeInterface sharedService] checkNewVersion];
        }
  • Multiple reminders: A pop-up appears every time the client calls the upgrade check interface. Use this mode when a new version has been available for some time and you want to prompt users more frequently.

  • Forced reminder: A pop-up appears every time the client calls the upgrade check interface, with no cancel button. Users cannot continue using the app without upgrading. Use this mode to retire old client versions.

Related links

Code examples