Commit c877ffec by zhangyunjie

启动SDK方法

parent e3871fa2
......@@ -60,12 +60,11 @@
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([OffcnIMSocketManager defaultService].IMConnectStatus != OffcnIMConnectStatusSuccess) {
//建立连接
// [[OffcnIMSocketManager defaultService] connectIMServerWithAccount_id:@"ce0819db8391f1e7258a71cc9e2c3235" token:@"fadbce3f4929b6bdee0617fee34e32ae"];
}
//进入前台,清除推送角标
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
......@@ -73,22 +72,12 @@
// [JPUSHService setBadge:0];
}
- (void)applicationWillTerminate:(UIApplication *)application {
//断开连接
[[OffcnIMSocketManager defaultService] disConnectIMServer];
}
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)(void))completionHandler{
}
/**
* 远程推送注册成功
*
* @param deviceToken deviceToken
*/
//远程推送注册成功
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
// 25bb75ac 3ffcebd7 90d9f517 1ebca904 154a367a 87781e5d b9ea288e 37fdf487
NSLog(@"-----deviceToken ---- ---- %@ devDesc ---%@", deviceToken,deviceToken.description);
......@@ -103,10 +92,7 @@
// applicationIconBadgeNumber
}
/**
* 注册失败
*
*/
//注册失败
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
NSLog(@"注册失败 ---- %@",error);
......@@ -133,33 +119,10 @@
NSLog(@"接收到远程推送通知 ---- %@", userInfo);
[AppDelegate didReceiveRemoteNotification:userInfo];
/*
"message" : "您的车辆京KKKKKK于2016-4-22 驶入邯郸",
"aps" : {
"alert" : "This is some fancy message.",
"badge" : 1,
"sound" : "您的车辆京KKKKKK于2016-4-22 驶入邯郸"
};
*/
// application.applicationIconBadgeNumber -=1;
//将推送消息以alert形式呈现
NSString *message = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
UILocalNotification *backgroudMsg = [[UILocalNotification alloc] init];
if (backgroudMsg) {
backgroudMsg.timeZone = [NSTimeZone defaultTimeZone];
backgroudMsg.alertBody = @"VoIP来电";
backgroudMsg.alertAction = @"查看";
NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
backgroudMsg.userInfo = infoDic;
[[UIApplication sharedApplication] presentLocalNotificationNow:backgroudMsg];
//[self cerateAVAudioPlayer];
}
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
NSLog(@"接收到本地推送通知 ---- %@", notification.userInfo);
......
//
//
......@@ -22,8 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
//收到通知
+(void)didReceiveRemoteNotification:(NSDictionary *)userInfo;
//后台收到消息本地推送
+(void)manualSendLocalNotificationWithModel:(OffcnIMModel *)model;
@end
NS_ASSUME_NONNULL_END
......
//
//
......@@ -83,19 +83,4 @@
[[OffcnIMZYJFMDBHandler sharedInstance] insertChatInfoToFMDBWithModel:body];
[[OffcnIMZYJFMDBHandler sharedInstance] chatlistCacheInfo:body callback:nil];
}
+(void)manualSendLocalNotificationWithModel:(OffcnIMModel *)model{
dispatch_sync(dispatch_get_main_queue(), ^{
UILocalNotification *backgroudMsg = [[UILocalNotification alloc] init];
if (backgroudMsg) {
backgroudMsg.timeZone = [NSTimeZone defaultTimeZone];
backgroudMsg.alertBody = @"您有一条新的消息";
backgroudMsg.applicationIconBadgeNumber = 1;
backgroudMsg.alertAction = @"查看";
NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
backgroudMsg.userInfo = infoDic;
[[UIApplication sharedApplication] presentLocalNotificationNow:backgroudMsg];
}
});
}
@end
//
//
......@@ -28,6 +28,8 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
@interface OffcnIMSocketManager : NSObject
@property (nonatomic, copy) NSString *msg_fromId;//发送消息的用户id
@property (nonatomic, copy) NSString *token;//发送消息的用户token
@property (nonatomic, assign) OffcnIMConnectStatus IMConnectStatus;
......@@ -44,6 +46,9 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
//断开连接
-(void)disConnectIMServer;
//后台收到消息本地推送
-(void)manualSendLocalNotificationWithModel:(OffcnIMModel *)model;
@end
NS_ASSUME_NONNULL_END
//
//
......@@ -19,6 +19,8 @@
@property (nonatomic, strong) OIMCoreAdapter *adapter;
@property (nonatomic, strong) NSMutableArray *msgArr;
@property (nonatomic, assign) BOOL isActive;
@property (nonatomic) UIBackgroundTaskIdentifier backgroundTask;
@end
......@@ -46,7 +48,7 @@ static OffcnIMSocketManager *socketManager;
[self.adapter Initialize];
self.adapter.delegate = self;
self.isActive = YES;
self.backgroundTask = UIBackgroundTaskInvalid;
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
......@@ -65,6 +67,11 @@ static OffcnIMSocketManager *socketManager;
selector:@selector(appDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[defaultCenter addObserver:self
selector:@selector(appWillTerminateNotification)
name:UIApplicationWillTerminateNotification
object:nil];
}
return self;
}
......@@ -84,6 +91,7 @@ static OffcnIMSocketManager *socketManager;
// tls = ["disable", "enable"]
self.msg_fromId = account_id;
self.token = token;
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObjectOnSafe:@"39.102.42.185" forKey:@"server_ip"];
......@@ -204,6 +212,23 @@ static OffcnIMSocketManager *socketManager;
}
}
-(void)manualSendLocalNotificationWithModel:(OffcnIMModel *)model{
if (self.isActive) {
dispatch_sync(dispatch_get_main_queue(), ^{
UILocalNotification *backgroudMsg = [[UILocalNotification alloc] init];
if (backgroudMsg) {
backgroudMsg.timeZone = [NSTimeZone defaultTimeZone];
backgroudMsg.alertBody = @"您有一条新的消息";
backgroudMsg.applicationIconBadgeNumber = 1;
backgroudMsg.alertAction = @"查看";
NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
backgroudMsg.userInfo = infoDic;
[[UIApplication sharedApplication] presentLocalNotificationNow:backgroudMsg];
}
});
}
}
- (void)appWillResignActive {
// [self.sessionManager disconnectWithDisconnectHandler:nil];
......@@ -215,6 +240,8 @@ static OffcnIMSocketManager *socketManager;
// return;
// }
self.isActive = NO;
__weak typeof(self) weakSelf = self;
self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
......@@ -223,7 +250,17 @@ static OffcnIMSocketManager *socketManager;
}
- (void)appDidBecomeActive {
// [self.sessionManager connectToLast:nil];
self.isActive = YES;
if (self.IMConnectStatus != OffcnIMConnectStatusSuccess && self.msg_fromId && self.token) {
//建立连接
[self connectIMServerWithAccount_id:self.msg_fromId token:self.token];
}
}
- (void)appWillTerminateNotification {
//断开连接
[self disConnectIMServer];
}
- (void)endBackgroundTask {
......@@ -237,5 +274,6 @@ static OffcnIMSocketManager *socketManager;
[defaultCenter removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[defaultCenter removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
}
@end
......@@ -9,9 +9,10 @@
#import "ViewController.h"
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSocketManager.h"
#import "OffcnZYJTestDataStorageView.h"
#import "AppDelegate+OffcnIMPush.h"
#import "OffcnZYJTestDataStorageView.h"
@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet UIButton *changeEnvironmentBtn;
......@@ -94,7 +95,8 @@
msg = [msg stringByAppendingString:IMModel.body.msg.url?IMModel.body.msg.url:@"nil"];
}
[AppDelegate manualSendLocalNotificationWithModel:IMModel];
//进入后台正常连接socket,使用此方法本地推送接受到的消息
[[OffcnIMSocketManager defaultService] manualSendLocalNotificationWithModel:IMModel];
// [weakSelf tipMessageWithTitle:@"收到消息" message:msg];
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment