iOS JShare Integration Guide

Use Suggestions

This article is a standard integration guide document for the JShare iOS SDK. The matching SDK version is V1.5.0 and later.

  • If you want a quick test, please refer to this article to run through the Demo within minutes.

  • All documents, including all guides, APIs, and tutorials, are available on the Jiguang Doc website. Updated versions of this document will be posted to the site in a timely manner.

Description of Product Function

JShare SDK allows your application to support multi-platform sharing. It does not take time to understand and integrate the SDK of each social sharing platform, which can effectively reduce the package size.

Main Scenes:

  • Share content to three major social platforms including QQ, WeChat and Sina Weibo.

  • Access to personal information on QQ, WeChat, Sina Weibo for third-party login.

  • Share content to Facebook and Messenger, and access to personal information of Facebook users for third-party logins.

  • Share content to twitter and get personal information of twitter users for third-party login.

Content of Integrated Package

  • jshare-ios-x.x.x.a static library

  • jcore-ios-x.x.x.a static library

  • header file of JSHARE SDK entrance JSHAREService.h

  • A complete iOS Demo project that demonstrates the basic usage of the JSHARE SDK. Refer to this Demo when configuring the SDK.

Versions Supported by iOS SDK

Currently JSHARE only supports iOS 7 and above iOS versions.

Quick Experience

  • Double-click on JShareDemo.xcodeproj in the archive to open Demo;

  • Modify the value of appKey in AppDelegate.m;

  • Fill in the Bundle id of the certificate you uploaded in application created by Jiguang, in the [General] page -> [Identity] -> [Bundle Identifier]

  • Run to Install Demo to Real Machine.

JSHARE SDK Integration Steps

Option 1: Import by Cocoapods

  • Download address through Cocoapods:

    1. pod 'JShare'
  • If you need to install a specific version, use the following method (take the 1.3.0 version as an example):

    1. pod 'JShare', '1.3.0'

Option 2: Import Manually

  • Unzip the package and copy all the files under Lib into the project to start using the SDK.

  • Add related framework dependencies:

    • UIKit

    • SystemConfiguration

    • CoreTelephony

    • CoreGraphics

    • Security

    • Foundation

    • CoreLocation

    • CoreFoundation

    • CFNetwork

    • libz.tbd

    • libresolv.tbd

  • The location where AppDelegate.m refers header file

  1. // 引入 JSHARE 功能所需头文件
  2. #import "JSHAREService.h"
  3. // 如果需要使用 idfa 功能所需要引入的头文件(可选)
  4. #import <AdSupport/AdSupport.h>

Description of SDK Main Interfaces

JSHARELaunchConfig class: The JSHARE SDK launches the configuration model.

JSHAREService class contains all interfaces of share SDK.

method - setupWithConfig

Interface Definition:

+(void)setupWithConfig:(JSHARELaunchConfig *)config

Interface Description:

Initialize the interface. It is recommended to call in application:didFinishLaunchingWithOptions:.

Parameter Description:

  • config:Instance of the JSHARELaunchConfig class

Call Example:

  1. JSHARELaunchConfig *config = [[JSHARELaunchConfig alloc] init];
  2. config.appKey = @"AppKey copied from JiGuang Portal application";
  3. config.SinaWeiboAppKey = @"374535501";
  4. config.SinaWeiboAppSecret = @"baccd12c166f1df96736b51ffbf600a2";
  5. config.SinaRedirectUri = @"https://www.jiguang.cn";
  6. config.QQAppId = @"1105864531";
  7. config.QQAppKey = @"glFYjkHQGSOCJHMC";
  8. config.WeChatAppId = @"wxa2ea563906227379";
  9. config.WeChatAppSecret = @"bb63c0a06bf0ee7f633a5bc44304d110";
  10. config.FacebookAppID = @"1847959632183996";
  11. config.FacebookDisplayName = @"JShareDemo";
  12. config.TwitterConsumerKey = @"4hCeIip1cpTk9oPYeCbYKhVWi";
  13. config.TwitterConsumerSecret = @"DuIontT8KPSmO2Y1oAvby7tpbWHJimuakpbiAUHEKncbffekmC";
  14. [JSHAREService setupWithConfig:config];
  15. [JSHAREService setDebug:YES];

method - share

Interface Definition:

+(void)share:(JSHAREMessage *)message handler:(JSHAREStateHandler)handler

Parameter Description:

  • message:Instance of the JSHAREMessage class

  • handler:Callback after JSHAREStateHandler is shared

Call Example:

  1. JSHAREMessage *message = [JSHAREMessage message];
  2. message.text = @"JShare SDK 支持主流社交平台、帮助开发者轻松实现社会化功能!";
  3. message.platform = JSHAREPlatformQQ;
  4. message.mediaType = JSHAREText;
  5. [JSHAREService share:message handler:^(JSHAREState state, NSError *error) {
  6. NSLog(@"分享回调");
  7. }
  8. }];

method - handleOpenUrl

Interface Definition:

+(BOOL)handleOpenUrl:(NSURL *)url

Interface Description:

Callback interface of sharing, required!

Below iOS 9, call application:handleOpenURL: of Appdelegate ; above iOS 9, call application of Appdelegate: openURL: options.

Parameter Description:

  • url:url of the callback.

Call Example:

  1. //目前适用所有 iOS 系统
  2. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
  3. [JSHAREService handleOpenUrl:url];
  4. return YES;
  5. }
  6. //仅支持 iOS9 以上系统,iOS8 及以下系统不会回调
  7. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
  8. [JSHAREService handleOpenUrl:url];
  9. return YES;
  10. }

method - getSocialUserInfo

Interface Definition:

+(void) getSocialUserInfo:(JSHAREPlatform)platform handler:(JSHARESocialHandler)handler

Interface Description:

By invoking interface for user information acquiring, obtain the user ID, avatar, and other data on the third-party platform to complete the construction of account system

Parameter Description:

  • platform: JSHAREPlatform enumeration type.

  • handler: JSHARESocialHandler gets callbacks of user information

Call Example:

  1. [JSHAREService getSocialUserInfo:platfrom handler:^(JSHARESocialUserInfo *userInfo, NSError *error) {
  2. NSString *alertMessage;
  3. NSString *title;
  4. if (error) {
  5. title = @"失败";
  6. alertMessage = @"无法获取到用户信息";
  7. }else{
  8. title = userInfo.name;
  9. alertMessage = [NSString stringWithFormat:@"昵称: %@\n 头像链接: %@\n 性别: %@\n",userInfo.name,userInfo.iconurl,userInfo.gender == 1? @"男" : @"女"];
  10. }
  11. UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:title message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  12. dispatch_async(dispatch_get_main_queue(), ^{
  13. [Alert show];
  14. });
  15. }];

For other interfaces, please see JSHAREService.h.

Configuration in Xcode

Configure ApplicationQueriesSchemes

Under iOS9/10, you need to add a whitelist for applications to jump to, that is, LSApplicationQueriesSchemes, otherwise you will return NO when the SDK determine whether to use canOpenURL to jump, and then only share/failed to share with webview.

Add the application whitelist to the info.plist of the project:

  • Right click info.plist

  • Select source code

  • Add the following content

  1. <key>LSApplicationQueriesSchemes</key>
  2. <array>
  3. <!-- 微信 URL Scheme 白名单-->
  4. <string>wechat</string>
  5. <string>weixin</string>
  6. <!-- 新浪微博 URL Scheme 白名单-->
  7. <string>sinaweibohd</string>
  8. <string>sinaweibo</string>
  9. <string>sinaweibosso</string>
  10. <string>weibosdk</string>
  11. <string>weibosdk2.5</string>
  12. <!-- QQ、Qzone URL Scheme 白名单-->
  13. <string>mqqapi</string>
  14. <string>mqq</string>
  15. <string>mqqOpensdkSSoLogin</string>
  16. <string>mqqconnect</string>
  17. <string>mqqopensdkdataline</string>
  18. <string>mqqopensdkgrouptribeshare</string>
  19. <string>mqqopensdkfriend</string>
  20. <string>mqqopensdkapi</string>
  21. <string>mqqopensdkapiV2</string>
  22. <string>mqqopensdkapiV3</string>
  23. <string>mqqopensdkapiV4</string>
  24. <string>mqzoneopensdk</string>
  25. <string>wtloginmqq</string>
  26. <string>wtloginmqq2</string>
  27. <string>mqqwpa</string>
  28. <string>mqzone</string>
  29. <string>mqzonev2</string>
  30. <string>mqzoneshare</string>
  31. <string>wtloginqzone</string>
  32. <string>mqzonewx</string>
  33. <string>mqzoneopensdkapiV2</string>
  34. <string>mqzoneopensdkapi19</string>
  35. <string>mqzoneopensdkapi</string>
  36. <string>mqqbrowser</string>
  37. <string>mttbrowser</string>
  38. <!-- Facebook URL Scheme 白名单-->
  39. <string>fbapi</string>
  40. <string>fb-messenger-api</string>
  41. <string>fbauth2</string>
  42. <string>fbshareextension</string>
  43. <!-- Twitter URL Scheme 白名单-->
  44. <string>twitter</string>
  45. <string>twitterauth</string>
  46. </array>

Add URL Types

Format description of URL Schemes for each platform:

Platform Format Example
WeChat WeChat appKey wxa2ea563906227379
QQ Need to add: “tencent” + Tencent QQ Internet app appID If appID is 1105864531, then the value fo URL Schemes will be tencent1105864531
Sina Weibo “wb”+Sina appKey If appKey is 727232518, then the value fo URL Schemes will be wb727232518
Facebook “fb”+FacebookAppID If appID is 1847959632183996, then the value of URL Schemes will be fb1847959632183996
Twitter “twitterkit-”+TwitterConsumerKey If TwitterConsumerKey is 4hCeIip1cpTk9oPYeCbYKhVWi, then the value of URL Schemes will be twitterkit-4hCeIip1cpTk9oPYeCbYKhVWi

URL Types Settings

Set in [TARGETS] -> [Info] in the Xcode project directory:

iOS JShare Integration Guide - 图1

HTTPS Settings

Apple will implement ATS (App Transport Security) starting from 2017. All network applications under review will support HTTPS. The following configurations will be invalidated. Please prepare in advance.

At present, JShare supports webpage sharing in the absence of a Sina Weibo client. However, because Sina Weibo’s api has not yet been optimized for https, it needs a corresponding https setting for Sina. In JShare, the webpage sharing of Sina Weibo is turned off by default. To use this function, you need to set the isSupportWebSina attribute to YES in the instance of the JSHARELaunchConfig class.

A project compiled with iOS10 SDK will use the SSL security protocol to perform network transmission by default, that is, HTTPS. If you still use the HTTP protocol to request the network, a system exception will be reported and interrupt the request. Currently, you can use HTTP to keep your network connection in this way:

  1. <key>NSAppTransportSecurity</key>
  2. <dict>
  3. <!-- 配置允许 http 的任意网络 End-->
  4. <key>NSExceptionDomains</key>
  5. <dict>
  6. <!-- 集成新浪微博对应的 HTTP 白名单-->
  7. <key>sina.com.cn</key>
  8. <dict>
  9. <key>NSIncludesSubdomains</key>
  10. <true/>
  11. <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
  12. <true/>
  13. <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
  14. <false/>
  15. </dict>
  16. <key>sinaimg.cn</key>
  17. <dict>
  18. <key>NSIncludesSubdomains</key>
  19. <true/>
  20. <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
  21. <true/>
  22. <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
  23. <false/>
  24. </dict>
  25. <key>sinajs.cn</key>
  26. <dict>
  27. <key>NSIncludesSubdomains</key>
  28. <true/>
  29. <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
  30. <true/>
  31. <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
  32. <false/>
  33. </dict>
  34. <key>sina.cn</key>
  35. <dict>
  36. <!-- 适配 iOS10 -->
  37. <key>NSExceptionMinimumTLSVersion</key>
  38. <string>TLSv1.0</string>
  39. <key>NSIncludesSubdomains</key>
  40. <true/>
  41. <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
  42. <false/>
  43. </dict>
  44. <key>weibo.cn</key>
  45. <dict>
  46. <!-- 适配 iOS10 -->
  47. <key>NSExceptionMinimumTLSVersion</key>
  48. <string>TLSv1.0</string>
  49. <key>NSIncludesSubdomains</key>
  50. <true/>
  51. <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
  52. <false/>
  53. </dict>
  54. <key>weibo.com</key>
  55. <dict>
  56. <!-- 适配 iOS10 -->
  57. <key>NSExceptionMinimumTLSVersion</key>
  58. <string>TLSv1.0</string>
  59. <key>NSIncludesSubdomains</key>
  60. <true/>
  61. <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
  62. <true/>
  63. <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
  64. <false/>
  65. </dict>
  66. <!-- 新浪微博-->
  67. </dict>
  68. </dict>

end