- 2015.04.03 / JIN DU MIN : 制作文档
Build Architecture
iOS Version
把PMS.framework移动到App项目里面
TARGET > Build Phases > Link Binary With Libraries里选择 Add Other… 添加 PMS.framework
TARGET > Build Phases > Link Binary With Libraries里添加PMS的4个框架
Project > Apple LLVM 6.0 - Language - Modules的 Enable Modules (C and Objective-C)值改为YES
******-Info.plist
文件里设定 AppKey和 ApiUrl
想要使用PMS的Class #import <PMS/PMS.h>
后可以使用
接收推送后的处理动作有3种
case1 分辨方法
case1,2 分辨方法
// 请求APNS服务的Token
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {
// Xcode5.x 以下不能编译
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
if([UIApplication sharedApplication].currentUserNotificationSettings.types == UIUserNotificationTypeNone){
// 设置系统通知 == OFF
}
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
if([UIApplication sharedApplication].enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone){
// 设置系统通知 == OFF
}
}
-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
{
// [PMS deviceCert]在setPushToken里自动运行
[PMS setPushToken:devToken];
}
-(void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
[PMS deviceCert];
}
为了接收[PMS setPushToken:devToken], [PMS deviceCert]的通信结果体现PMSDelegate的(Optional,不需要接收结果的话不需要体现)
@interface AppDelegate : UIResponder <UIApplicationDelegate, PMSDelegate>
// PMS Delegate 设置
[PMS setDelegate:self];
#pragma mark - PMS Delegate implements
// APP里接收推推送后[PMS receivePush:tagString]呼出时反应的delegate
-(void)pmsDidReceivePush:(PMSModelMessage *)resultModel Tag:(NSString *)tag
{
if(resultModel && [resultModel isSuccess]){
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:resultModel.pushTitle
message:resultModel.pushMsg
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
// [PMS setPushToken:devToken] 呼出时反应的 delegate
-(void)pmsSetPushTokenComplete:(PMSResult*)result
{
NSLog(@"pmsSetPushTokenComplete : %@", result);
}
// 用Batch实行点击传送后反应的delegate
-(void)pmsSendClickMsgComplete:(PMSResult *)result
{
NSLog(@"pmsSendClickMsgComplete : %@", result);
}
// 用Batch实行已读delegate
-(void)pmsSendReadMsgComplete:(PMSResult *)result
{
NSLog(@"pmsSendReadMsgComplete : %@", result);
}
[PMS setConfigWithNotiFlag:YES MsgFlag:NO CompleteBlock:^(PMSResult *result) {
// TODO Something
}];
//确认本地值
[PMS getNotiFlag]; // 推送接收允许
[PMS getMsgFlag]; // 储存到收件箱允许
// 确认服务器上设置的值(需要网络请求不推荐 )
[PMS getConfigFlagsWithCompleteBlock:^(PMSResult *result, BOOL notiFlag, BOOL msgFlag) {
// TODO Something
}];
登入PMS?
644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b
端机的测试用户
一般登入
[PMS loginWithCustId:@"用户ID" CompleteBlock:^(PMSResult *result) {
if([result isSuccess]){
// TODO Something... on login Success
}else{
// TODO Something... on login Fail!!!
}
}];
使用DeviceCert登入
[PMS deviceCertWithCustId:tfCustId.text UserData:dict CompleteBlock:^(PMSResult *result) {
if([result isSuccess]){
// TODO Something... on cert Success
}else{
// TODO Something... on cert Fail!!!
}
}];
信息类型
排列// 通过网络通信获取组
[PMS loadGrpListWithCompleteBlock:^(PMSResult *result, NSArray *groupArray) {
if([result isSuccess]){
// 储存获取组后在表里显示
mGroupData = [NSMutableArray arrayWithArray:groupArray];
[mGroupTableView reloadData];
}else{
// 加载TODO组时失败
}
}];
// 不通过网络通讯直接在本地数据库里获取组
mGroupData = [NSMutableArray arrayWithArray:[PMS loadGrpListWithCompleteBlock:nil]];
[mGroupTableView reloadData];
@interface MessageBoxViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
{
NSString *targetGrpCode; // 用分组方式获取信息
int deleteCount; // 需要删除功能
int page; // 储存现在查询的页
int totalCount; // 储存所有信息数量
}
- (void) loadNextPageData
{
if(mMsgData == nil){
// 储存从PMS接收的信息的NSMutableArray alloc
mMsgData = [NSMutableArray new];
}
if(page == 0){
// 页数等于0的时候需要刷新或者其他方法从1页开始呼出
[mMsgData removeAllObjects];
[mMsgTableView setContentOffset:CGPointZero animated:NO];
}
// 使用网络来接收
[PMS loadMsgListWithGrpCode:targetGrpCode
Page:++page
PerPage:perPage
CompleteBlock:^(PMSResult *result, NSArray *msgArray) {
if([result isSuccess]){
// 添加接收DATA
[mMsgData addObjectsFromArray:msgArray];
dispatch_async(dispatch_get_main_queue(), ^{
[mMsgTableView reloadData];
});
// 重置newCount (接收新的信息计数为零)
[PMS resetNewCountWithGrpCode:targetGrpCode];
// 确认信息数量(需要判断是否有下一页)
totalCount = [PMS getMessageCountWithGrpCode:targetGrpCode];
}else{
// 失败时-1页面
page--;
}
}];
}
// 섹션당 로우개수는 서버에서 받아온 메시지 데이터 길이
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (mMsgData) {
return [mMsgData count];
}else{
return 0;
}
}
// 在UITableView显示单元
// 实现分页可能不一样
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"MessageTableViewCell";
MessageTableViewCell *cell = (MessageTableViewCell *)[mMsgTableView dequeueReusableCellWithIdentifier: identifier];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:identifier owner:self options:nil] objectAtIndex:0];
}
PMSModelMessage *msg = [mMsgData objectAtIndex:[indexPath row]];
[cell renderingCellWithMsg:msg];
// 获取下一页(剩余5个的时候)
if([indexPath row] >= mMsgData.count - 5
&& mMsgData.count+deleteCount < totalCount){
[self loadNextPageData];
}
return cell;
}
// 选着row的时候移动到详细页面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
PMSModelMessage *msg = [mMsgData objectAtIndex:[indexPath row]];
[msg setReadYn:@"Y"];
MessageDetailViewController *msgDetailViewController = [[MessageDetailViewController alloc] initWithNibName:@"MessageDetailViewController" bundle:nil msg:msg];
[self.navigationController pushViewController:msgDetailViewController animated:YES];
}
信息是软删除, 不会跟服务器同步
[PMS deleteMsgWithUserMsgId:currentMsg.userMsgId];
[PMS restoreMsgWithUserMsgId:currentMsg.userMsgId];
// 请求Batch方式
[PMS sendReadMsgEventWithMsgId:currentMsg.msgId];
// 请求Direct方式
[PMS sendReadMsgEventWithMsgId:currentMsg.msgId CompleteBlock:^(PMSResult *result) {
// TODO 结束请求后处理
}];
接收推送后呼叫[PMS receivePush:tagString:],把该推送信息详细内容在pmsDidReceivePush里返还.
运行APP时接收推送处理例子
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[PMS receivePush:userInfo Payload:userInfo tagString:@"didReceive"];
}
if(launchOptions){
[PMS receivePush:launchOptions Payload:launchOptions tagString:@"didFinish"];
}
-(void)pmsDidReceivePush:(PMSModelMessage *)resultModel Payload:(NSDictionary *)payload Tag:(NSString *)tag
{
if(resultModel && [resultModel isSuccess]){
// 成功接收推送
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:resultModel.pushTitle message:resultModel.pushMsg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}else{
// 没有接收推送时利用Payload弹出
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"[Push message]" message:[[payload objectForKey:@"aps"] objectForKey:@"alert"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
DeviceCert
NewMsg
Message
MessageGroup
MessageCount
SetConfig
ReadMsg
ClickMsg
<A>
标签时呼叫的方法,暂时IOS上使用不了Login
删除信息
恢复信息
Batch强制开始
PMSConfig.h
修改PMS主要设定值,没有设置是用默认值代替// 修改AppKey和 MsgApiUrl
// 在PMSConfig重设置的话在plist的值是无效的
[PMSConfig setApiUrl:@"http://apiUrl.com"];
[PMSConfig setAppKey:@"YourAppKey"];
// msgApi版本设置(在指定的情况下使用)
[PMSConfig setMsgApiVersionMajor:2 minor:0 patch:5];
// 设置网络timeout时间
[PMSConfig setNetworkTimeout:10.0f];
// 设置当页显示几条信息
[PMSConfig setPerPage:20];
// 请求再联网次数
[PMSConfig setReattemptCount:3];
// 设置readMsg, clickMsg的Batch timer interval
[PMSConfig setTimerInterval:10.0f];
// 设置加密(制定情况下使用)
[PMSConfig cryptEnable:YES];
// 设置输出PMSLog(发生错误时设置为YES可以查看错误)
[PMSConfig logEnable:YES];
// 设置输出PMSApiLog (发生错误时设置为YES可以查看错误)
[PMSConfig apiLogEnable:YES];
// 设置是否储存Msg到本地(制定情况下使用)
[PMSConfig useMsgDB:YES];
// 设置PushToken为UUID
// 设置为YES的话不能推送,而且不能发布APNS Token. 也不能在PMS系统上登入
[PMSConfig usePushTokenToUUID:NO];
// Sample Code
// 不需要全部传送,只传送需要的值
NSMutableDictionary* userData = [NSMutableDictionary new];
[userData setValue:@"Tester" forKey:@"custName"];
[userData setValue:@"19850101" forKey:@"birthday"];
[userData setValue:@"01012345678" forKey:@"phoneNumber"];
[userData setValue:@"loc 1" forKey:@"location1"];
[userData setValue:@"loc 2" forKey:@"location2"];
[userData setValue:@"M" forKey:@"gender"]; // M or F
[userData setValue:@"data1" forKey:@"data1"];
[userData setValue:@"data2" forKey:@"data2"];
[userData setValue:@"data3" forKey:@"data3"];
Code | 说明 |
---|---|
000 | 通信成功 |
100 | 参数错误,必输参数遗漏 |
101 | 参数错误,参数大小有误 |
102 | 参数错误, 无效参数 |
103 | 解密有误 |
104 | JSON形式有误 |
105 | Session有误(Timeout 等) |
106 | 加密有误 |
109 | 无法使用的msgApi |
110 | 其他错误(msgApi) |
120 | 其他错误(无法确认) |
130 | - |
510 | 无效的App key |
Code | 说明 |
---|---|
700 | SDK 其他错误, 确认PMSResult的信息 |
702 | UUID 生成有误 |
720 | 点击链接有误 |
730 | 已读有误 |
920 | 联网超时,确认MsgApi地址 |