Integrate with iOS

更新时间:
复制 MD 格式

The mobile scheduling center is supported in baselines 10.1.68 and later. This topic describes how to integrate the mobile scheduling center with iOS.

Integrate the SDK

Select an integration method based on your connection type.

Integration methods

You can integrate Mobile PaaS (mPaaS) in three main ways:

Integrate based on the mPaaS framework

The mPaaS iOS framework is a development framework derived from the Alipay client. This framework directly takes over the application lifecycle and is responsible for the entire application's startup hosting and application lifecycle management. Based on the framework design, it isolates business logic into independent modules, promoting high cohesion and low coupling between modules. For more information, see mPaaS framework overview.

Quickly build a new application based on the mPaaS framework. For the steps, see Integrate based on the mPaaS framework.

Integrate into an existing project using the mPaaS plugin

If you have a single project where all SDKs are directly linked, integrate using the mPaaS plugin. For the steps, see Integrate into an existing project using the mPaaS plugin.

Integrate into an existing project using CocoaPods

If your existing project uses CocoaPods to manage SDK dependencies, integrate using CocoaPods. For the steps, see Integrate into an existing project using CocoaPods.

Component integration

  • Integrate mPaaS using mPaaSPlugin.

    1. In Xcode, choose Editor > mPaaS > Edit Project to open the Edit Project page.

    2. Select Mobile Dispatch, save, and then click Start Editing. This adds the Mobile Dispatch module to the module list.

  • Integrate mPaaS using CocoaPods.

    1. In the Podfile, add mPaaS_pod 'mPaaS_MDC'.

    2. In the terminal, run pod install to complete the integration.

Use the SDK

Parameter settings

Rewrite the category configuration of MPNetworkInterface.

  • Port switch: Specifies whether to use the port sent by the mobile scheduling center. This switch is disabled by default.

  • Backup IP: The backup IP address for requests to the mobile scheduling center. The default value is nil.

  • Domain group: The domain name group configured in the console. The default value is nil.

  • Domain list: The list of domain names configured in the console. The default value is nil.

// Mobile scheduling center Port switch
- (BOOL)useMdcPort {
    return NO;
}

// Backup IP. The default value is nil.
- (NSString *)amdcBackupIp
{
    return @"192.168.1.1";
}

// The domain name group configured in the console. The default value is nil.
- (NSString *)amdcDomainGroup
{
    return @"test";
}

// The list of domain names configured in the console. The default value is nil.
- (NSArray *)amdcDomainList
{
    return @[@"www.test.com"];
}

API reference

Initialization

Initialize the mobile scheduling center and refresh the data.

  • Run the initialization operation only once. If you modify the domain IP information in the console or change the configuration on the client, call the initServiceWithDelegate method to refresh the data.

  • If the mobile scheduling center is not initialized, other APIs cannot be used.

/// Initialize
+ (void)initServiceWithDelegate:(id<MPDNSNetworkDelegate>)delegate;

MPDNSNetworkDelegate callback

// code is the RPC response code. 1000 indicates success.
- (void)didDNSNetworkInfoRefresh:(int)code;

Refresh data

Refresh domain name IP information.

/// Refresh data
+ (void)refresh;

Get all IP information

Get all domain name IP information returned by the mobile scheduling center.

/// Get all IP information
+ (NSArray<MPDNSNetworkInfo *> *)getNetworkInfoList;

Get IP information for a single domain name

Return the IP information for a single domain name.

/// Get IP information for a single domain name
/// @param host The domain name
+ (MPDNSNetworkInfo *)getNetworkInfoByHost:(NSString *)host;

Return result description

MPDNSNetworkInfo

@interface MPDNSNetworkInfo : NSObject

/// Domain name
@property (nonatomic, copy) NSString *host;
/// CNAME
@property (nonatomic, copy) NSString *cname;
/// List of IP information
@property (nonatomic, copy) NSArray<MPDNSNetworkIP *> *ipList;

@end

MPDNSNetworkIP

@interface MPDNSNetworkIP : NSObject

/// IP address
@property (nonatomic, copy) NSString *ip;
/// IP port
@property (nonatomic, assign) NSInteger port;
/// IP type (4: IPv4, 6: IPv6)
@property (nonatomic, assign) NSInteger ipType;

@end

MPMDCNetworkInfo

// IP address
@property (nonatomic, copy) NSString *ip;
// IP port
@property (nonatomic, copy) NSNumber *port;
// Mobile scheduling center timestamp
@property (nonatomic, copy) NSString *timestamp;

Code example

#import <MPMDC/MPMDC.h>

// Initialize the mobile scheduling center. This is run only once.
[MPDNSNetworkService initServiceWithDelegate:nil];

// Refresh the mobile scheduling center. Manually run the refresh operation if you modify the IP in the console or change the configuration on the client.
[MPDNSNetworkService refresh];

RPC integration

RPC integration with the mobile scheduling center requires configuring a switch by rewriting the category of DTRpcInterface.

  • Mobile scheduling center switch: Enables or disables the mobile scheduling center. After you enable this switch, you must still manually call the initialization method for the mobile scheduling center. This switch is disabled by default.

  • IPv6 switch: Specifies whether to use the IPv6 address returned by the mobile scheduling center to send requests. If you enable this switch, requests are sent using the IPv6 address by preference. This switch is disabled by default.

  • Port switch: Specifies whether to use the port sent by the mobile scheduling center.

// Mobile scheduling center switch
- (BOOL)isHTTPDNS {
    return YES;
}

// IPv6 switch
- (BOOL)ipv6Enabled {
    return NO;
}

// Mobile scheduling center Port switch
- (BOOL)useMdcPort {
    return NO;
}
Note
  • RPC does not automatically initialize the mobile scheduling center. To use the center, manually call its initialization method.

  • A single RPC request is not retried. To switch to the next IP, send the request again.