iOS SDK介绍

更新时间:2016/05/23 访问次数:51566

Demo快速体验

1 注册百川应用(已有忽略).

下载demoIOS推送 Demo

 

解压demo,用xcode打开demo。

4下载iOS SDK,将下载oneSDK里的图?替换demo里的图片,图片名称为yw_1222.jpg.【注意:下载SDK时,因为是体验demo, bundle id应该是demo的bundle id。

勾选云推送功能

SDK下载后解压出来里面有一张安全图片(yw_1212.jpg)。由于DEMO中,SDK包已经附加好了,只需要将下载的SDK中的yw_1212.jpg替换demo?里的图片即可,勿修改文件名。

5 配置推送

iOS私有通道消息直接运行demo,在控制台推送即可。

 

apns通知推送需要配置证书:参见证书配置

客户端集成

1.1 IOS推送配置证书

IOS推送证书:ios推送证书设置指南

1.2 IOS SDK集成

SDK下载:点击查看。【因为自己的工程,bundle id应该是自己工程的bundle id,注意与demo体验的区别

SDK集成参见:sdk集成

ALBBSDK.framework,ALBBPush.framework依赖以下公共类:

1、CoreTelephony.framework

2、SystemConfiguration.framework

3、libz.tbd 

4、libresolv.tbd

5、CoreLocation.framework

6、secuity.framework

7、CFNetwork.framework

8、AlicloudUtils.framework

引用 ALBBPush/CloudPushSDK.h ALBBSDK/ALBBSDK.h类 

1.3 ios apns与tcp通道消息配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<br><br>        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 
    [self registerAPNS:application :launchOptions];
    [self init_tae];
    [self registerMsgReceive];
 
    return YES;
}<br><br>
 
- (void)init_tae{
 
 
    [[ALBBSDK sharedInstance] setDebugLogOpen:YES];//开发阶段打开日志开关,方便排查错误信息
   NSLog(@"enter  initialize");
    [[ALBBSDK sharedInstance] asyncInit:^{
        NSLog(@"init success");
    } failure:^(NSError *error) {
        NSLog(@"init failure, %@", error);
    }];
    NSLog(@"end  initialize");
 
    [self registerPushNofitication];
    [self registerMsgReceive];
    [self registerAPNS:application :launchOptions];
     
 
}
 
// 注册
- (void) registerPushNofitication {
     
    /**
     注册apns
     */
    /// 需要区分iOS SDK版本和iOS版本。
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
         
    } else
#endif
    {
        /// 去除warning
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#pragma clang diagnostic pop
    }
    NSLog(@"registerNotication");
}
#pragma mark 注册苹果的推送
-(void) registerAPNS :(UIApplication *)application :(NSDictionary *)launchOptions{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [application registerForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    }
    [CloudPushSDK handleLaunching:launchOptions]; // 作为 apns 消息统计
}
 
#pragma mark 注册接收CloudChannel 推送下来的消息
- (void) registerMsgReceive {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageReceived:) name:@"CCPDidReceiveMessageNotification" object:nil]; // 注册
}
// 推送下来的消息抵达的处理示例(上线前如果不使用消息,则不要此外代码))
- (void)onMessageReceived:(NSNotification *)notification {
    NSData *data = [notification object];
    NSString *message = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    // 报警提示
    if(![NSThread isMainThread])
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"有消息抵达" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
            [alertView show];
        });
    } else {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"有消息抵达" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
        [alertView show];
    }
}
 
 
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
}
 
// 苹果推送服务回调,注册 deviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [CloudPushSDK registerDevice:deviceToken];
     
    NSString *token =   [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
                          stringByReplacingOccurrencesOfString:@">" withString:@""]
                         stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSLog(@"deviceToken:%@",token);
}
 
//通知统计回调
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
    [CloudPushSDK handleReceiveRemoteNotification:userInfo];
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
    NSLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error);
}

API文档

API说明

绑定账号接口

1
2
3
4
5
6
7
8
9
10
11
                    /**
 * 绑定账号
 */
+(void) bindAccount:(NSString *) account withCallback:(CCPOperateResult) callback;
 
/**
 *  去除账号绑定
 *
 *  @param account 账号
 */
+(void) unbindAccount: (NSString *) account withCallback:(CCPOperateResult) callback;

自定义标签调用接口

1
2
3
4
5
6
7
8
9
10
                    /**
 * 增加自定义的tag, 目前只支持12个自定义的tag
 */
+(void) addTag:(NSString *) tag withCallback:(CCPOperateResult) callback;
 
 
/**
 * 删除自定义的tag, 目前只支持12个自定义的tag
 */
+(void) removeTag:(NSString *) tag withCallback:(CCPOperateResult) callback;

设置免打扰调用接口

1
+(void) setAcceptTime:(UInt32) startH startMS:(UInt32) startMS endH:(UInt32)endH endMS: (UInt32)endMS withCallback:(CCPOperateResult) callback;

获取apns推送下来的deviceToken接口

1
2
3
4
5
                    /**
 * 获取deiviceToken
 *
 */
+(NSString *)getDeviceToken:(NSData *)deviceToken;

获取当前sdk版本的接口

1
2
3
4
                    /**
 * 得到推送的当前版本
 **/
+(NSString *) getVersion;

获取deviceId

1
2
3
4
5
6
7
8
                    /**
 *  获取deiviceId
 *
 *  @param deviceToken
 *
 *  @return
 */
+(NSString *)getDeviceId:(NSData *)deviceToken;

apns相关的接口

APNS注册deviceToken

1
2
3
4
5
6
7
8
                    /**
 *  会将deviceToken放至服务器
 *
 *  @param deviceToken 苹果apns 服务器推送下来的 deviceToken
 *
 *  @return
 */
+(void)registerDevice:(NSData *) deviceToken;

apns相关的接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
                    /**
 *  用户通过通知打开应用,检查lanchOptions,主要用来发送统计回执
 *
 *  @param launchOptions
 */
+(void)handleLaunching:(NSDictionary *)launchOptions;
 
 
/**
 *  处理苹果anps 推送下来的消息,主要是用来统计回执
 *
 *  @param userInfo
 */
+(void)handleReceiveRemoteNotification:(NSDictionary *)userInfo;

消息接收接口

1
2
3
4
5
6
7
8
9
                    - (void) listenerOnChannelOpened {
 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onChannelOpened:) name:@"CCPDidChannelConnectedSuccess" object:nil]; // 注册
}
 
// 推送下来的消息抵达的处理示例
- (void)onChannelOpened:(NSNotification *)notification {
   // doSomething
}

 

推送

进入管理控制台,点击配置。

cerf

配置好证书以后应用即可推送。控制台使用见控制台介绍 

通知和消息推送可以通过通过api集成到服务端,对应的api接口:

发送消息

发送通知

高级接口【对应高级设置】

参见服务端SDK介绍

 

技术咨询

 

 

旺旺群:1074804791

FAQ

关于此文档暂时还没有FAQ
返回
顶部