iOS SDK Integration Guide

Integration instructions

Applicable to SDK version

This document is compatible with the JMessage iOS SDK V3.0.0 and later. If users who have integrated previous versions or users who have integrated JPush want to integrate IM at the same time, plese see Precautions below.

System Requirements and Development Environment

  • The JMessage iOS SDK supports iOS 7 and later versions.

Integration Steps

1、Create an application on the Jiguang Web Console

Log in to the Jiguang Web Console, create applications, and upload APNs certificates. If you do not know much about Apple APNs certificates, please refer to the iOS Certificate Setup Guide.

jmessage_ios

AppKey is automatically generated to identify the application after successful creation. This will be used later.

jmessage_ios

2、SDK import

Cocoapods import

Download address via Cocoapods

  1. pod 'JMessage'

Use below if you need to install the specified version

  1. pod 'JMessage', :head

3. Skip step 3 if importing SDK via Cocoapods

Manually import

Download latest SDK on JMessage official website

  1. Add the JMessage.framework file to the project.

  2. Link jcore-ios-x.x.x.a (x.x.x as jcore version number) in the JMessafe.framework directory to the project.

3、Add the necessary framework

  • CoreTelephony.framework

  • CoreAudio.framework

  • CoreGraphics.framework

  • SystemConfiguration.framework

  • CFNetwork.framework

  • Security.framework

  • AudioToolbox.framework

  • MobileCoreServices.framework

  • libz.dylib

  • libsqlite3.0.dylib

  • libresolv.tbd

4、Build Settings configuration

  • Add 1 item in Project Configuration, Build Settings, Other Linker Flags
  1. -ObjC

5、Initialize JMessage SDK

In the following method of the project’s AppDelegate, call the corresponding SDK method

  1. #import "AppDelegate.h"
  2. #import <JMessage/JMessage.h>
  3. @implementation AppDelegate
  4. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  5. // Required - 启动 JMessage SDK
  6. [JMessage setupJMessage:launchOptions appKey:JMSSAGE_APPKEY channel:nil apsForProduction:NO category:nil];
  7. // Required - 注册 APNs 通知
  8. if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  9. //可以添加自定义categories
  10. [JMessage registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
  11. UIUserNotificationTypeSound |
  12. UIUserNotificationTypeAlert)
  13. categories:nil];
  14. } else {
  15. //categories 必须为nil
  16. [JMessage registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
  17. UIRemoteNotificationTypeSound |
  18. UIRemoteNotificationTypeAlert)
  19. categories:nil];
  20. }
  21. return YES;
  22. }
  23. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  24. // Required - 注册token
  25. [JMessage registerDeviceToken:deviceToken];
  26. }
  27. @end

Detailed usage

For details, please refer to the SDK Development Guide or check the Demo provided below.

Precautions

User upgrades in versions prior to V3.0.0

The upgrade steps are as follows:

  1. Replace the old file with the same name under the original project with the new version of the JMessage.framework file.

  2. Link JCore.a in JMessage.framework to the project.

  3. Implement the method of registering original Apns and uploading the token by the method of the JMessage class. The implementation is as follows:

  1. [JMessage registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert) categories:nil];
  2. [JMessage registerDeviceToken:deviceToken];

Monitor modification of connection status notification name

The previous versions of the JMessage iOS SDK V3.0.0 monitor connection status of the SDK through the Push notification. It is provided by the JMessage after updating. The original notification name is

  1. extern NSString *const kJPFNetworkIsConnectingNotification; // 正在连接中
  2. extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
  3. extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
  4. extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
  5. extern NSString *const kJPFNetworkFailedRegisterNotification; //注册失败
  6. extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
  7. extern NSString *const kJPFNetworkDidReceiveMessageNotification; // 收到消息
  8. extern NSString *const kJPFServiceErrorNotification; // 错误提示

Now change to

  1. extern NSString *const kJMSGNetworkIsConnectingNotification; // 正在连接中
  2. extern NSString *const kJMSGNetworkDidSetupNotification; // 建立连接
  3. extern NSString *const kJMSGNetworkDidCloseNotification; // 关闭连接
  4. extern NSString *const kJMSGNetworkDidRegisterNotification; // 注册成功
  5. extern NSString *const kJMSGNetworkFailedRegisterNotification; // 注册失败
  6. extern NSString *const kJMSGNetworkDidLoginNotification; // 连接成功
  7. extern NSString *const kJMSGNetworkDidReceiveMessageNotification; // 收到消息
  8. extern NSString *const kJMSGServiceErrorNotification; // 错误提示

Integrate JMessage based on JPush

JMessage iOS SDK V3.0.0 and later versions no longer include the functions of JPush. Users who use JPush need to integrate the JPush SDK separately. Refer to JPush Integration Guide for integration steps.

Note the following points

  1. Version requirements: Supports JPush V3.0.1 or later version. JCore requires V1.1.0 or later version.

  2. Replacement of JCore: The downloaded JPush SDK zip package also contains the name jcore-ios-xxxa Lib. When integrating, it is necessary to note that only one jcore is kept in the project. If the Jcore version contained in JPush and JMessage is inconsistent, keep the latest version of jcore.

JMessage Demo

JMessage provides a complete application of JChat in the IM scenario. It is an IM App for reference. JChat iOS project source code, open source has been placed on Github. In the downloaded SDK archive, there is also JChat source code.

Technical Support

E-mail contact: support@jiguang.cn