iOS Integration
<p>[TOC]</p>
<table>
<thead>
<tr>
<th>version</th>
<th>timMSLDe</th>
<th>modify</th>
<th>author</th>
<th>mark</th>
</tr>
</thead>
<tbody>
<tr>
<td>v1.0</td>
<td>2019/08/05</td>
<td>first written</td>
<td>jack.deng</td>
<td>none</td>
</tr>
</tbody>
</table>
<h3>1. Abstract</h3>
<ul>
<li>MSSDK(Micro Services SDK) is a new standard SDK that idreamsky provided at 2019.</li>
<li>supported iOS 8+, architecture: arm64,armv7,x86_64, Xcode version Xcode 10+</li>
<li>this doc is for the beginner of iOS MSSDK. The details of API please read </li>
</ul>
<p><em>mark: the current version support the min capacity of Account,Payment,Analytics for publish channel of AppStore</em></p>
<p><strong> Special attention: If the game developers are about to access is the type of online games (leisure games can be ignored), in order to login and pay security, the server access related interface is required. Specific access documents can be viewed <a href="https://www.showdoc.cc/mssdk?page_id=2647897962757260">MSSDK server access documents</a></strong></p>
<h3>2. Prepare</h3>
<h4>2.1 Apply for iDreamsky Parameter</h4>
<ul>
<li>Login in <a href="http://dev.idreamsky.com/">iDreamsky developer platform</a> to create the game, you can get the Release Key、Release Secret and Game Id.These parameter should be writted in SDK config File.</li>
<li>If you have no developer account, please contact us.</li>
</ul>
<h4>2.2 Set payment callback of game payment.</h4>
<ul>
<li>The callback URL is using for receiving the notification of account changes. When charged, MSSDK will send a request for synchronization.</li>
<li>Config Entrance: <a href="http://dev.idreamsky.com/">iDreamsky developer platform</a></li>
<li><strong>Attention</strong> If product are send by client, you needn't config the callback URL. You must set the delegate of redelivery order. For details see 4.2.2 section.</li>
</ul>
<h4>2.3 Design Integration Case</h4>
<h5>2.3.1 Login Page(required)</h5>
<ul>
<li>When enter the game first time, loading game resource, then enter 「Game Login Page」</li>
<li>Click 「帐号登录」 at 「Game Login Page」will show login panel, click 「快速进入」 will enter guset login flow.</li>
<li>Design Reference:
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/Android/guide-UI/guide_03.png?raw=true" alt="image" /></li>
</ul>
<h5>2.3.2 UserCenter(required)</h5>
<ul>
<li>After login, You game should provide an 「user center」for maintaining user profile.</li>
<li>Design Reference 1: provide an login entrance at Main Page
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/Android/guide-UI/guide_04.png?raw=true" alt="image" /></li>
<li>Design Reference 2: provide an user Center entrance at game setting
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/Android/guide-UI/guide_05.png?raw=true" alt="image" /></li>
</ul>
<h3>3 SDK Integration</h3>
<h4>3.1 Get SDK config File</h4>
<ul>
<li>Get MSSDK resource (*.zip),Please contact US.</li>
<li>Get msConfig.json
<h4>3.2 Config develop environment</h4>
<h5>3.2.1 add SDK to Project</h5></li>
<li>unzip MSSDK zip file
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_01.png?raw=true" alt="image" /></li>
<li>add MSSDK framework to project
step1: right click the xcode prject directory, click <strong>Add Files to "your project name"</strong>
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_02.png?raw=true" alt="image" />
step2: at pop window, click <strong>MSLDSDK directory</strong>, select <strong>Create groups</strong>, click <strong>Add</strong> button and done.
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_03.png?raw=true" alt="image" /></li>
</ul>
<h5>3.2.2 add framework search path</h5>
<p>select <strong>TARGETS</strong> –> <strong>Build Settings</strong> –> <strong>Framework Search Paths</strong>, add MSSDK framework search path.(support absolute path and relative path, no space)
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_04.png?raw=true" alt="image" /></p>
<h5>3.2.3 embedded frameworks</h5>
<p>select <strong>TARGETS</strong> –> <strong>General</strong> –> <strong>Embedded Binaries</strong> -> <strong>+</strong>, addd MSSDK framework file
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_05.png?raw=true" alt="image" /></p>
<h5>3.2.4 Build Settings Flags</h5>
<p>select <strong>TARGETS</strong> –> <strong>Build Settings</strong> -> <strong>Other Linker Flags</strong>,add <strong>-ObjC</strong> add <strong>-lz</strong>
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_06.png?raw=true" alt="image" /></p>
<h5>3.2.5 add config file to the project</h5>
<p>add MSSDK config file <strong>msConfig.json</strong> to main directory of project </p>
<h4>3.3 SDK initialization</h4>
<ul>
<li>at head of AppDelegate.m, import SDK header file
<pre><code class="language-objective-C">#import <MSLDSDK/MSLDSDK.h></code></pre></li>
<li>call initialization method at the below function of AppDelegate
<pre><code class="language-objective-C"></code></pre></li>
<li>(BOOL)application:(UIApplication <em>)application didFinishLaunchingWithOptions:(nullable NSDictionary </em>)launchOptions
<pre><code></code></pre></li>
<li>call initialization method
<em>note:the initialization parameter is readed from msConfig.json, if parameters are error, initialization will failed. Only success the SDK can be used</em></li>
</ul>
<pre><code class="language-objective-C">// init MSSDK
[[MSLDSDK sharedInstance] initSDKWithSuccess:^(NSString *msg, id data) {
NSLog(@"init MSLD SDK success!");
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
NSLog(@"init MSLD SDK failed! code = %ld, msg = %@", code, msg);
}];</code></pre>
<h3>4 function integration</h3>
<ul>
<li>Only success initiate SDK can make the each function work.</li>
<li>MSSDK contains Account system, payment system and Log system.</li>
</ul>
<h4>4.1 integrate Account System</h4>
<ul>
<li>MSSDK provide login, user center, real name certify function.</li>
</ul>
<h5>4.1.1 Login panel</h5>
<ul>
<li>The login panel provide UI for logining.</li>
<li>
<p>The current version support phone/code, phone/password and guest login.
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_07.png?raw=true" alt="image" /></p>
</li>
<li>demo:</li>
</ul>
<pre><code class="language-objective-C">// url parameter is ROUTE_ACCOUNT_LOGIN
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_ACCOUNT_LOGIN param:@{} success:^(NSString *msg, id data) {
// Login success. data are login info
NSString *logStr = [NSString stringWithFormat:@"show login panel success!, msg = %@, data = %@", msg, data];
NSLog(@"%@",logStr);
[self changeToMainScence];// after login, go to appropriate scence.
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// Login failure, in this block, it returns failure reason. Game logic should deal the business according the error code
if (MSLDErrorCodeUIUserClose == code) {
// user cancel login
NSLog(@"user cancel login:%@",msg);
} else {
// login failure
NSString *logStr = [NSString stringWithFormat:@"login panel failed!code = %ld, msg = %@, data = %@", code, msg, errorData];
NSLog(@"%@", logStr);
}
}];</code></pre>
<h5>4.1.2 Guest Login</h5>
<ul>
<li>Create a guest account for player. Player can enter the game directly to play the game and not be verified.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_ACCOUNT_GUEST_LOGIN param:@{} success:^(NSString *msg, id data) {
// Login success
NSString *logStr = [NSString stringWithFormat:@"Quick login success!, msg = %@, data = %@", msg, data];
NSLog(@"%@",logStr);
[self changeToMainScence]; // after login, go to appropriate scence.
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
if (MSLDErrorCodeUIUserClose == code) {
// user cancel login
NSLog(@"user cancel login:%@",msg);
} else {
// login failure
NSString *logStr = [NSString stringWithFormat:@"Quick login failed!code = %ld, msg = %@, data = %@", code, msg, errorData];
NSLog(@"%@", logStr);
}
}];</code></pre>
<h5>4.1.3 Auto Login</h5>
<ul>
<li>use case: If login success last time, it will not verify the player. Enter the game directly.</li>
<li>SDK Logic: When call auto login, SDK will login with last login info.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_ACCOUNT_AUTO_LOGIN param:@{} success:^(NSString *msg, id data) {
// auto login success
NSString *logStr = [NSString stringWithFormat:@"auto login success!, msg = %@, data = %@", msg, data];
NSLog(@"%@", logStr);
// enter game main interface
[self changeToMainScence];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// auto login failure
NSString *logStr = [NSString stringWithFormat:@"自动登录失败!code = %ld, msg = %@, data = %@", code, msg, errorData];
NSLog(@"%@", logStr);
// enter game login interface
[self.gameLoginView setHidden:NO];
}];</code></pre>
<h5>4.1.4 monitor login callback</h5>
<ul>
<li>when something changes, MSSDK notify the game by global delegate.</li>
<li>game monitor the login event in delegate and deal the busniess.</li>
<li>step 1:set global delegate at appropriate place.</li>
</ul>
<pre><code class="language-objective-C">[MSLDSDK sharedInstance].delegate = self;</code></pre>
<ul>
<li>step 2:imply the delegate method and deal the event</li>
</ul>
<pre><code class="language-objective-C">-(void)onMSLDSDKEvent:(MSLDSDKGlobalEvent)eventID msg:(NSString *)msg data:(id)data{
switch (eventID) {
case MSLDSDKLogOut:
//user logout
NSLog(@"onEvennt MSLDSDKLogOut");
break;
case MSLDSDKSwitchAccount:
// user switch the account
NSLog(@"onEvennt MSLDSDKSwitchAccount");
break;
default:
break;
}
}</code></pre>
<h5>4.1.5 user center</h5>
<ul>
<li>user center provide a UI display user profile. It contains user info, phone bind, set password, real name and switch account etc.
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_08.png?raw=true" alt="image" /></li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_ACCOUNT_USER_CENTER param:nil success:^(NSString *msg, id data) {
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
if (MSLDErrorCodeUIUserClose == code) {
// user cancel
}
}];</code></pre>
<h5>4.1.6 real name verify(Optional)</h5>
<ul>
<li>There's entrance of real name verify at user center panel. In other case you can show real name panel directly</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_ACCOUNT_AUTHENTICATION param:nil success:^(NSString *msg, id data) {
// real name success
MSLDLOG(@"auth success! msg: %@, data :%@",msg, data);
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// real name failure
MSLDLOG(@"auth fail! code %li msg: %@, data :%@", (long)code, msg, errorData);
}];</code></pre>
<h5>4.1.7 Get User Info(Optional)</h5>
<ul>
<li>Get current logined account info.,For details please read <a href="http://confluence.idreamsky.com:8090/x/IwEz">《iOS MSSDK API文档》</a></li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">MSLDAccount *account = [[MSLDSDK sharedInstance] syncActionWithLDUrl:ROUTE_ACCOUNT_LOGINED_USER_INFO param:nil];</code></pre>
<h5>4.1.8 Best practice</h5>
<ul>
<li>Best practice for calling Login API
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_09.jpg?raw=true" alt="image" /></li>
</ul>
<h4>4.2 Integration Payment System</h4>
<ul>
<li>MSSDK provide apple IAP for games.</li>
<li>pre conditon:config game product info at <a href="https://itunesconnect.apple.com/">App Store product</a> and <a href="https://www.showdoc.cc/mssdk?page_id=2615409307929897">contact us</a> </li>
<li>attention: You'd better integration account system before integration payment system.</li>
<li>the client must imply the redelivery order delegate. For details please read section 4.2.2.</li>
</ul>
<h5>4.2.1 purchase product</h5>
<ul>
<li>purchase API has no UI, you should implement your purchase UI. </li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">// Calling this API with parameter of pruduct info will begin the pruchase flow. The product info you input should be same as apple backend configed
NSString * item = @"test01";//same as apple backend configed
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_PAY_PURCHASE_PRODUCT param:@{ PAY_PRODUCT_ID: item, PAY_EXTRA_INFO: @"" } success:^(NSString *msg, id data) {
// pay success. will return order info. The game can valid the payment according the order info and send items.
MSLDOrder *order = data;
NSLog(@"pay success! orderID : %@, productID :%@", order.orderID, order.productID);
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// pay failure
NSLog(@"pay error! %@", msg);
}];</code></pre>
<h5>4.2.2 implement redelivery order logic(must implement if you send item from client)</h5>
<ul>
<li>The purchase flow may break by some exception, when recoveryed, MSSDK will notify the game in the delegate.</li>
<li>The game should valid the order to send items.</li>
<li><strong>Attention</strong>:If you send items by <strong>server</strong>, the server notification shall prevail. This delegate notification only reference.</li>
<li><strong>Attention</strong>:If you send items by <strong>client</strong>, using this notification, valid it and send item. Make sure not missing send or repeat send.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">// set delegate
[MSLDSDK sharedInstance].delegate = self;
// implement delegate method
-(void)onMSLDSDKEvent:(MSLDSDKGlobalEvent)eventID msg:(NSString *)msg data:(id)data{
switch (eventID) {
case MSLDSDKRedeliveryOrder:
//wehn receive this notificaton, you can continue the next flow of purchase.
MSLDOrder *order = data;
NSLog(@"onEvennt MSLDSDKRedeliveryOrder");
break;
case ...:
...
default:
break;
}
}</code></pre>
<h5>4.2.3 restore transactions</h5>
<ul>
<li>query the purchase history of current app ID of this game.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_PAY_RESTORE_TRANSACTIONS param:nil success:^(NSString *msg, id data) {
// query successful. sent items
NSArray *restoreTransactions = data;
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// query failed
}];</code></pre>
<h5>4.2.4 query product info</h5>
<ul>
<li>query product info by product ID.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_PAY_QUERY_PRODUCT param:@{ PAY_PRODUCT_ID: @"test01" } success:^(NSString *msg, id data) {
// query product info successful
NSDictionary *productInfo = data;
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// failed
}];</code></pre>
<h5>4.2.5 query subscriptions</h5>
<ul>
<li>query subscriptions of current account</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_PAY_QUERY_SUBSCRIPTIONS param:nil success:^(NSString *msg, id data) {
// success query
NSArray<MSLDSubscription *> *subscriptions = data;
if (subscriptions.count > 0) {
}
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
// failure
}];</code></pre>
<h4>4.3 Integration Share System</h4>
<ul>
<li>MSSDK provide share to Weichat or QQ.</li>
<li>support scence below:
<ol>
<li>share image to wechat session, wechat time line, QZone, QQ friend</li>
<li>share web page to wechat session, wechat friend, QZone, QQ friend</li>
<li>share wechat miniprogram to wechat session</li>
<li>open wechat miniprogram</li>
</ol></li>
</ul>
<h5>4.3.1 QQ Share</h5>
<h6>4.3.1.1 Apply QQ Share parameter</h6>
<ul>
<li>visit <a href="https://connect.qq.com/index.html">QQ互联平台</a> to create app and obtain QQ AppId.</li>
<li>fill MSSDK config file("msConfig.json") with QQ AppId.</li>
</ul>
<h6>4.3.1.2 Add QQ SDK to Xcode project</h6>
<ul>
<li>add frameworks below to Xcode project:
<ol>
<li>MSLDShareSDK.framework</li>
<li>MSLDQQShareSDK.framework</li>
<li>MSLDQQPackage.framework</li>
</ol></li>
<li>the details about adding please read section 3.2.1,section 3.2.2 and section 3.2.3.</li>
</ul>
<h6>4.3.1.3 config QQ info to Xcode project</h6>
<ul>
<li>URL Scheme config</li>
</ul>
<p>select <strong>TARGETS</strong> –> <strong>Info</strong> –> <strong>URLTypes</strong>,add a <strong>URL scheme</strong>,named "tencent+QQAppId",for example: tencent222222
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_10.png?raw=true" alt="image" /></p>
<ul>
<li>config LSApplicationQueriesSchemes</li>
</ul>
<p>select <strong>TARGETS</strong> –> <strong>Info</strong> –> <strong>LSApplicationQueriesSchemes</strong>,add the content below:</p>
<pre><code class="language-xml"><key>LSApplicationQueriesSchemes</key>
<array>
<string>mqq</string>
<string>mqqapi</string>
<string>mqqwpa</string>
<string>mqqbrowser</string>
<string>mttbrowser</string>
<string>mqqOpensdkSSoLogin</string>
<string>mqqopensdkapiV2</string>
<string>mqqopensdkapiV3</string>
<string>mqqopensdkapiV4</string>
<string>wtloginmqq2</string>
<string>mqzone</string>
<string>mqzoneopensdk</string>
<string>mqzoneopensdkapi</string>
<string>mqzoneopensdkapi19</string>
<string>mqzoneopensdkapiV2</string>
<string>mqqapiwallet</string>
<string>mqqopensdkfriend</string>
<string>mqqopensdkdataline</string>
<string>mqqgamebindinggroup</string>
<string>mqqopensdkgrouptribeshare</string>
<string>tencentapi.qq.reqContent</string>
<string>tencentapi.qzone.reqContent</string>
</array></code></pre>
<ul>
<li>share callback:for get the share result</li>
</ul>
<pre><code class="language-Objective-C">- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[[MSLDSDK sharedInstance] msld_application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
return YES;
}
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
[[MSLDSDK sharedInstance] msld_application:app openURL:url options:options];
return YES;
}
#endif</code></pre>
<h6>4.3.1.4 call QQ share</h6>
<ul>
<li>share image to QQ friend:</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareImageToQQ
{
// image data
// NSDictionary *param = @{ SHARE_SCENE: SHARE_QQ_FRIENDS,
// @"image": [UIImage imageNamed:@"bg_launcher"],
// @"thumbImage": [UIImage imageNamed:@"bg_launcher"],
// @"title": @"image title",
// @"description": @"description of image" };
// image data
NSDictionary *param = @{ SHARE_SCENE: SHARE_QQ_FRIENDS,
@"image": UIImagePNGRepresentation([UIImage imageNamed:@"bg_launcher"]),
@"thumbImage": [UIImage imageNamed:@"bg_launcher"],
@"title": @"image title",
@"description": @"description of image" };
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_IMAGE param:param success:^(NSString *msg, id data) {
[MSLDLog logDebug:@"share image to QQ successfully! msg=%@", msg];
[UIAlertView msld_showAlertDialogWithTitle:@"提示" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
[UIAlertView msld_showAlertDialogWithTitle:@"提示" msg:msg];
[MSLDLog logDebug:@"share image to QQ failed! code:%ld,msg=%@,errorData=%@", code, msg, errorData];
}];
}</code></pre>
<ul>
<li>share image to QZone:</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareImageToQzone
{
NSDictionary *param = @{ SHARE_SCENE: SHARE_QQ_QZONE,
@"image": [UIImage imageNamed:@"bg_launcher"],
@"thumbImage": [UIImage imageNamed:@"bg_launcher"],
@"title": @"image title",
@"description": @"description of image" };
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_IMAGE param:param success:^(NSString *msg, id data) {
[MSLDLog logDebug:@"share image to QZone successfully! msg=%@", msg];
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
[MSLDLog logDebug:@"share image to QZone failed! code:%ld,msg=%@,errorData=%@", code, msg, errorData];
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>share webpage to QQ friend:</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareWebToQQ
{
NSDictionary *param = @{ SHARE_SCENE: SHARE_QQ_FRIENDS,
@"webpageUrl": @"http://baidu.com",
@"thumbImage": [UIImage imageNamed:@"bg_launcher"],
@"title": @"image title",
@"description": @"description of image" };
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_WEBPAGE param:param success:^(NSString *msg, id data) {
[MSLDLog logDebug:@"share webpage to QQ successfully! msg=%@", msg];
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
[MSLDLog logDebug:@"share webpage to QQ failed! code:%ld,msg=%@,errorData=%@", code, msg, errorData];
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>share webpage to QZone:</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareWebToQzone
{
NSDictionary *param = @{ SHARE_SCENE: SHARE_QQ_QZONE,
@"webpageUrl": @"http://baidu.com",
@"thumbImage": [UIImage imageNamed:@"bg_launcher"],
@"title": @"titile",
@"description": @"description" };
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_WEBPAGE param:param success:^(NSString *msg, id data) {
[MSLDLog logDebug:@"share webpage to QZone successfully! msg=%@", msg];
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
[MSLDLog logDebug:@"share webpage to QZone failed! code:%ld,msg=%@,errorData=%@", code, msg, errorData];
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<h5>4.3.2 wechat share</h5>
<h6>4.3.2.1 apply wechat parameter</h6>
<ul>
<li>visit <a href="https://open.weixin.qq.com/">微信开放平台</a>create app and obtain AppId.</li>
<li>fill MSSDK config file("msConfig.json") with wechat AppId.</li>
</ul>
<h6>4.3.2.2 add wechat SDK to Xcode project</h6>
<ul>
<li>add frameworks below to XCode project:
1.MSLDShareSDK.framework
2.MSLDWeChatShareSDK.framework
3.MSLDWeChatPackage.framework</li>
<li>for details please reference section 3.2.1、section 3.2.2 and section 3.2.3</li>
</ul>
<h6>4.3.2.3 config wechat info to XCode Project</h6>
<ul>
<li>
<p>config URL Scheme :
select <strong>TARGETS</strong> –> <strong>Info</strong> –> <strong>URLTypes</strong>,add item <strong>URL scheme</strong>,named "wx+appid",for example: wx3f520918821729b6
<img src="https://github.com/veryitman/MSSDKResource/blob/mark-feature/iOS/guide-main/guide_11.png?raw=true" alt="image" /></p>
</li>
<li>Config LSApplicationQueriesSchemes</li>
</ul>
<p>select <strong>TARGETS</strong> –> <strong>Info</strong> –> <strong>LSApplicationQueriesSchemes</strong>,add weixin</p>
<pre><code class="language-xml"><key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
</array></code></pre>
<ul>
<li>share callback:for share result</li>
</ul>
<pre><code class="language-Objective-C">- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
[[MSLDSDK sharedInstance] msld_application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
return YES;
}
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
[[MSLDSDK sharedInstance] msld_application:app openURL:url options:options];
return YES;
}
#endif</code></pre>
<h6>4.3.2.4 call wechat share function</h6>
<ul>
<li>share image to wechat session</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareImageToWeChatSession
{
UIImage *image = [UIImage imageNamed:@"bg_launcher"];
UIImage *thumbImage = [UIImage imageNamed:@"AppIcon"];
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_IMAGE param:@{ SHARE_SCENE: SHARE_WECHAT_SESSION, @"image": image, @"thumbImage": thumbImage } success:^(NSString *msg, id data) {
MSLDLOG(@"--------- shareImageToWeChatSession success");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
MSLDLOG(@"--------- shareImageToWeChatSession fail");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>share image to timeline</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareImageToWeChatTimeLine
{
UIImage *image = [UIImage imageNamed:@"bg_launcher"];
UIImage *thumbImage = [UIImage imageNamed:@"AppIcon"];
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_IMAGE param:@{ SHARE_SCENE: SHARE_WECHAT_TIMELINE, @"image": image, @"thumbImage": thumbImage } success:^(NSString *msg, id data) {
MSLDLOG(@"--------- shareImageToWeChatTimeLine success");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
MSLDLOG(@"--------- shareImageToWeChatTimeLine fail");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>share webpage to wechat session</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareWebpageToWeChatSession
{
UIImage *image = [UIImage imageNamed:@"bg_launcher"];
NSString *webpageUrl = @"www.baidu.com";
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_WEBPAGE param:@{ SHARE_SCENE: SHARE_WECHAT_SESSION, @"thumbImage": image, @"webpageUrl": webpageUrl, @"title": @"title", @"description": @"description" } success:^(NSString *msg, id data) {
MSLDLOG(@"--------- shareWebpageToWeChatSession success");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
MSLDLOG(@"--------- shareWebpageToWeChatSession fail");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>share webpage to timeline</li>
</ul>
<pre><code class="language-Objective-C">- (void)shareWebpageToWeChatTimeLine
{
UIImage *image = [UIImage imageNamed:@"bg_launcher"];
NSString *webpageUrl = @"www.baidu.com";
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_WEBPAGE param:@{ SHARE_SCENE: SHARE_WECHAT_TIMELINE, @"thumbImage": image, @"webpageUrl": webpageUrl, @"title": @"title", @"description": @"description" } success:^(NSString *msg, id data) {
MSLDLOG(@"--------- shareWebpageToWeChatTimeLine success");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
MSLDLOG(@"--------- shareWebpageToWeChatTimeLine fail");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>分享微信小程序到微信会话</li>
</ul>
<ol>
<li>参数申请:在<a href="https://mp.weixin.qq.com/">微信公众平台</a>注册小程序并获取小程序原始id,具体联系渠道商务或技术中台-微信组。</li>
<li>注意事项:在<a href="https://open.weixin.qq.com/">微信开放平台</a>, 将应用所属的微信开发平台帐号绑定小程序,具体联系渠道商务。</li>
<li>调用示例:</li>
</ol>
<pre><code class="language-Objective-C">- (void)shareWeChatMiniPragram
{
NSString *userName = @"gh_cda1b47da577";//miniprogram original id
NSString *thumbImage = @"https://www.idreamsky.com/static/img/service/icon4.png";//miniprogram preview image 128k
NSString *url = @"https://www.idreamsky.com/";// for old version device whitch not support miniprogram, present webpage
NSString *path = @"";// the content path whitch will show. if nil, show main page.
NSString *title = @"title";//share title
NSString *description = @"description";//share description
NSNumber *miniprogramType = [NSNumber numberWithInt:0];//scence type(0:product 1:developer 2:test)
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_SHARE_MINI_PROGRAM param:@{ @"userName": userName, @"path": path, @"webpageUrl": url, @"withShareTicket": @"1", @"title": title, @"description": description, @"thumbImage": thumbImage, @"type": miniprogramType } success:^(NSString *msg, id data) {
MSLDLOG(@"--------- shareWeChatMiniPragram success");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
MSLDLOG(@"--------- shareWeChatMiniPragram fail");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
<ul>
<li>open miniprogram from app</li>
</ul>
<ol>
<li>appley parameter:在<a href="https://mp.weixin.qq.com/">微信公众平台</a>create app and obtain minipragram id.</li>
<li>atention:visit<a href="https://open.weixin.qq.com/">微信开放平台</a>bind miniprogram to wechat developer account.</li>
<li>
<p>Demo:</p>
<pre><code class="language-Objective-C">- (void)openWeChatMiniPragram
{
NSString *userName = @"gh_cda1b47da577";//miniprogram id
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_LAUNCH_MINI_PROGRAM param:@{ @"userName": userName } success:^(NSString *msg, id data) {
MSLDLOG(@"--------- openWeChatMiniPragram success");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
MSLDLOG(@"--------- openWeChatMiniPragram fail");
[UIAlertView msld_showAlertDialogWithTitle:@"message" msg:msg];
}];
}</code></pre>
</li>
</ol>
<h4>4.4 upload game data(DLOG SDK)</h4>
<ul>
<li>MSSDK has contain DLOG SDK, the game can upload the date, it will be display in a report forms</li>
<li>the DLOG dependence the Account System. You should integration the Account System at first.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C"> // upload game loading time
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_DLOG_LOADING_COMPLETED_EVENT param:@{ @"loadingTime": @1211 } success:^(NSString *msg, id data) {
NSLog(@"report success!");
} fail:^(MSLDErrorCode code, NSString *msg, id errorData) {
NSLog(@"report failed");
}];
// upload custom event
NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithCapacity:1];
[param setObject:@"login" forKey:DLOG_EVENT_ID];
[param setObject:@"captchaLogin" forKey:DLOG_EVENT_PARAM];
[param setObject:@{ @"captchaNumber": @"1111" } forKey:DLOG_EXTEND];
[[MSLDSDK sharedInstance] actionWithLDUrl:ROUTE_DLOG_CUSTOM_EVENT param:param success:nil fail:nil];</code></pre>
<h4>4.5 Other</h4>
<h5>4.5.1 Get config information(Optional)</h5>
<ul>
<li>get config information. Current version only support get channel ID.</li>
<li>Demo:</li>
</ul>
<pre><code class="language-objective-C">MSLDConfig *config = [[MSLDSDK sharedInstance] syncActionWithLDUrl:ROUTE_SDK_CONFIG param:nil];</code></pre>