iOS Quick access
Last updated:2022-05-12
Expand all
iOS Quick access
This article aims to guide users to quickly integrate push services. Please refer to the detailed integration steps. SDK Integration Guide。
Add project configuration
Import method
- Recommended use Cocoapods For the import method, select the latest version for integration.
pod 'JCore' // 可选项,也可由pod 'JPush'自动获取
pod 'JPush' // 必选项
注:如果无法导入最新版本,请执行 pod repo update master 这个命令来升级本机的 pod 库,然后重新 pod 'JPush'
pod 'JCore' // 可选项,也可由pod 'JPush'自动获取
pod 'JPush' // 必选项
注:如果无法导入最新版本,请执行 pod repo update master 这个命令来升级本机的 pod 库,然后重新 pod 'JPush'
This code block is shown in the floating window
- If you need to install the specified version, use the following method (with JPush 4.8.0 version as an example):
pod 'JCore', '3.2.3' // 可选项,也可由pod 'JPush'自动获取
pod 'JPush', '4.8.0' // 必选项
pod 'JCore', '3.2.3' // 可选项,也可由pod 'JPush'自动获取
pod 'JPush', '4.8.0' // 必选项
This code block is shown in the floating window
Things to note
- App Things to note when reviewing the Apple App Market:View solutions。
- App Choose to use None IDFA Version,View solutions。
- If manual integration is required,View integration tutorial。
Initialize push service
Global configuration
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
This code block is shown in the floating window
Add header file
Please add the following code to AppDelegate.m The location of the referenced header file.
// 引入 JPush 功能所需头文件
#import "JPUSHService.h"
#import <UserNotifications/UserNotifications.h>
// 引入 JPush 功能所需头文件
#import "JPUSHService.h"
#import <UserNotifications/UserNotifications.h>
This code block is shown in the floating window
Add to Delegate
for AppDelegate Add to Delegate, reference code:
@interface AppDelegate ()<JPUSHRegisterDelegate>
@end
@interface AppDelegate ()<JPUSHRegisterDelegate>
@end
This code block is shown in the floating window
Add initialization code
Add initialization APNs code
请将以下代码添加到
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//【注册通知】通知回调代理(可选)
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
}
请将以下代码添加到
- (void)application:(UIApplication)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData)deviceToken {
//sdk注册DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
请将以下代码添加到
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//【注册通知】通知回调代理(可选)
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
}
请将以下代码添加到
- (void)application:(UIApplication)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData)deviceToken {
//sdk注册DeviceToken
[JPUSHService registerDeviceToken:deviceToken];
}
This code block is shown in the floating window
Add initialization JPush code
请将以下代码添加到
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//【初始化sdk】
// notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil
[JPUSHService setupWithOption:launchOptions appKey:appKey
channel:channel
apsForProduction:isProduction
advertisingIdentifier:advertisingId];
}
请将以下代码添加到
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//【初始化sdk】
// notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil
[JPUSHService setupWithOption:launchOptions appKey:appKey
channel:channel
apsForProduction:isProduction
advertisingIdentifier:advertisingId];
}
This code block is shown in the floating window
Partial parameter description:
- appKey
- chooseJiguangConsole application, click "Settings" to get its appkey value. Please ensure that the in-app configuration appkey andJiguangGenerated after creating the application on the console appkey consistent.
- channel
- Specify the download channel of the application package. To facilitate statistics by channel, the specific value is defined by you, such as:App Store。
- apsForProduction
- 1.3.1 Version is added to identify the version used by the current application. APNs Certificate environment.
- 0 (default) means a development certificate is used, 1 means the application is released with a production certificate.
- Note: The value of this field must be consistent with Build Settings of Code Signing The configured certificate environment is consistent.
- advertisingIdentifier
- See details about IDFA。
Verify push results
- After the integration is completed, debug the project on a real machine. If the console outputs the following log, it means that you have successfully integrated.
2022-01-10 12:05:38.914868+0800 PushTest[329:9045] | JIGUANG | I - [JIGUANGTcpEventController]
----- register result -----
uid: 58446934317
registrationID:1517bfd3f70cc645a1c
2022-01-10 12:05:38.914868+0800 PushTest[329:9045] | JIGUANG | I - [JIGUANGTcpEventController]
----- register result -----
uid: 58446934317
registrationID:1517bfd3f70cc645a1c
This code block is shown in the floating window
- Get the log registrationID, and inJiguangconsole Create push Experience push notification service.
- After the push is completed, you can Push history View detailed data such as push status, push channel, delivery rate, etc.
Was this document helpful?