Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
OffcnIMSDKiOS
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
opensource
OffcnIMSDKiOS
Commits
bdb38571
Commit
bdb38571
authored
Sep 10, 2020
by
zhangyunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
推送
parent
77d1281e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
15 deletions
+100
-15
AppDelegate.m
OffcnIMSDKiOS/AppDelegate.m
+5
-5
AppDelegate+OffcnIMPush.h
...MSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.h
+8
-4
AppDelegate+OffcnIMPush.m
...MSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.m
+26
-5
OffcnIMSocketManager.m
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.m
+58
-1
ViewController.mm
OffcnIMSDKiOS/ViewController.mm
+3
-0
No files found.
OffcnIMSDKiOS/AppDelegate.m
View file @
bdb38571
...
@@ -39,7 +39,7 @@
...
@@ -39,7 +39,7 @@
//获取用户相关数据库,该方法在登陆或者第一次启动已登陆下执行
//获取用户相关数据库,该方法在登陆或者第一次启动已登陆下执行
[[
OffcnIMZYJFMDBHandler
sharedInstance
]
getUserDB
];
[[
OffcnIMZYJFMDBHandler
sharedInstance
]
getUserDB
];
//推送
//推送
[
self
registerOffcnUserNotificationSettingsWithApplication
:
application
options
:
launchOptions
];
[
AppDelegate
registerOffcnUserNotificationSettingsWithApplication
:
application
options
:
launchOptions
];
//获取网络状态和内部初始化处理
//获取网络状态和内部初始化处理
[[
OffcnIMSDKiOS
defaultService
]
startNotifierUseRealReachability
];
[[
OffcnIMSDKiOS
defaultService
]
startNotifierUseRealReachability
];
...
@@ -78,11 +78,11 @@
...
@@ -78,11 +78,11 @@
[[
OffcnIMSocketManager
defaultService
]
disConnectIMServer
];
[[
OffcnIMSocketManager
defaultService
]
disConnectIMServer
];
}
}
-
(
void
)
application
:(
UIApplication
*
)
application
handleEventsForBackgroundURLSession
:(
NSString
*
)
identifier
completionHandler
:(
void
(
^
)(
void
))
completionHandler
{
-
(
void
)
application
:(
UIApplication
*
)
application
handleEventsForBackgroundURLSession
:(
NSString
*
)
identifier
completionHandler
:(
void
(
^
)(
void
))
completionHandler
{
}
}
/**
/**
* 远程推送注册成功
* 远程推送注册成功
*
*
...
@@ -92,7 +92,7 @@
...
@@ -92,7 +92,7 @@
// 25bb75ac 3ffcebd7 90d9f517 1ebca904 154a367a 87781e5d b9ea288e 37fdf487
// 25bb75ac 3ffcebd7 90d9f517 1ebca904 154a367a 87781e5d b9ea288e 37fdf487
NSLog
(
@"-----deviceToken ---- ---- %@ devDesc ---%@"
,
deviceToken
,
deviceToken
.
description
);
NSLog
(
@"-----deviceToken ---- ---- %@ devDesc ---%@"
,
deviceToken
,
deviceToken
.
description
);
NSString
*
str
=
[
self
hexStringForData
:
deviceToken
];
NSString
*
str
=
[
AppDelegate
hexStringForData
:
deviceToken
];
[
OffcnIMSDKiOS
defaultService
].
deviceToken
=
str
;
[
OffcnIMSDKiOS
defaultService
].
deviceToken
=
str
;
NSLog
(
@"token--- %@"
,
str
);
NSLog
(
@"token--- %@"
,
str
);
//注册成功,返回token
//注册成功,返回token
...
@@ -118,7 +118,7 @@
...
@@ -118,7 +118,7 @@
-
(
void
)
application
:(
UIApplication
*
)
application
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
fetchCompletionHandler
:(
void
(
^
)(
UIBackgroundFetchResult
))
completionHandler
{
-
(
void
)
application
:(
UIApplication
*
)
application
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
fetchCompletionHandler
:(
void
(
^
)(
UIBackgroundFetchResult
))
completionHandler
{
NSLog
(
@"接收到远程推送通知Background ---- %@"
,
userInfo
);
NSLog
(
@"接收到远程推送通知Background ---- %@"
,
userInfo
);
[
self
didReceiveRemoteNotification
:
userInfo
];
[
AppDelegate
didReceiveRemoteNotification
:
userInfo
];
if
([
UIApplication
sharedApplication
].
applicationState
!=
UIApplicationStateActive
)
{
if
([
UIApplication
sharedApplication
].
applicationState
!=
UIApplicationStateActive
)
{
// [self pushNotificationDefaultController];
// [self pushNotificationDefaultController];
...
@@ -130,7 +130,7 @@
...
@@ -130,7 +130,7 @@
-
(
void
)
application
:(
UIApplication
*
)
application
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
{
-
(
void
)
application
:(
UIApplication
*
)
application
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
{
NSLog
(
@"接收到远程推送通知 ---- %@"
,
userInfo
);
NSLog
(
@"接收到远程推送通知 ---- %@"
,
userInfo
);
[
self
didReceiveRemoteNotification
:
userInfo
];
[
AppDelegate
didReceiveRemoteNotification
:
userInfo
];
/*
/*
"message" : "您的车辆京KKKKKK于2016-4-22 驶入邯郸",
"message" : "您的车辆京KKKKKK于2016-4-22 驶入邯郸",
...
...
OffcnIMSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.h
View file @
bdb38571
//
//
...
@@ -7,19 +7,23 @@
...
@@ -7,19 +7,23 @@
//
//
#import "AppDelegate.h"
#import "AppDelegate.h"
#import "OffcnIMModel.h"
NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_BEGIN
@interface
AppDelegate
(
OffcnIMPush
)
@interface
AppDelegate
(
OffcnIMPush
)
//注册通知
//注册通知
-
(
void
)
registerOffcnUserNotificationSettingsWithApplication
:(
UIApplication
*
)
application
options
:(
NSDictionary
*
)
launchOptions
;
+
(
void
)
registerOffcnUserNotificationSettingsWithApplication
:(
UIApplication
*
)
application
options
:(
NSDictionary
*
)
launchOptions
;
//解析deviceToken
//解析deviceToken
-
(
NSString
*
)
hexStringForData
:(
NSData
*
)
data
;
+
(
NSString
*
)
hexStringForData
:(
NSData
*
)
data
;
//收到通知
//收到通知
-
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
;
+
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
;
//后台收到消息本地推送
+
(
void
)
manualSendLocalNotificationWithModel
:(
OffcnIMModel
*
)
model
;
@end
@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
...
...
OffcnIMSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.m
View file @
bdb38571
//
//
...
@@ -12,10 +12,11 @@
...
@@ -12,10 +12,11 @@
#import "DataSafe.h"
#import "DataSafe.h"
#import "OffcnIMZYJFMDBHandler.h"
#import "OffcnIMZYJFMDBHandler.h"
#import "OffcnIMSocketManager.h"
#import "OffcnIMSocketManager.h"
#import <UIKit/UIKit.h>
@implementation
AppDelegate
(
OffcnIMPush
)
@implementation
AppDelegate
(
OffcnIMPush
)
-
(
void
)
registerOffcnUserNotificationSettingsWithApplication
:(
UIApplication
*
)
application
options
:(
NSDictionary
*
)
launchOptions
{
+
(
void
)
registerOffcnUserNotificationSettingsWithApplication
:(
UIApplication
*
)
application
options
:(
NSDictionary
*
)
launchOptions
{
// application.applicationIconBadgeNumber = 0;
// application.applicationIconBadgeNumber = 0;
if
([
UIDevice
currentDevice
].
systemVersion
.
doubleValue
>=
8
.
0
){
if
([
UIDevice
currentDevice
].
systemVersion
.
doubleValue
>=
8
.
0
){
...
@@ -28,11 +29,16 @@
...
@@ -28,11 +29,16 @@
}
}
if
(
launchOptions
[
UIApplicationLaunchOptionsRemoteNotificationKey
]){
if
(
launchOptions
[
UIApplicationLaunchOptionsRemoteNotificationKey
]){
// 跳转
NSDictionary
*
remoteUserInfo
=
launchOptions
[
UIApplicationLaunchOptionsRemoteNotificationKey
];
if
(
remoteUserInfo
)
{
NSLog
(
@"remoteUserInfo:%@"
,
remoteUserInfo
);
//APP未启动,点击推送消息,iOS10下还是跟以前一样在此获取
}
}
}
}
}
-
(
NSString
*
)
hexStringForData
:(
NSData
*
)
data
{
+
(
NSString
*
)
hexStringForData
:(
NSData
*
)
data
{
if
(
data
==
nil
)
{
if
(
data
==
nil
)
{
return
nil
;
return
nil
;
...
@@ -46,7 +52,7 @@
...
@@ -46,7 +52,7 @@
return
hexString
;
return
hexString
;
}
}
-
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
{
+
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
{
OffcnIMPushModel
*
IMModel
=
[
OffcnIMPushModel
mj_ZYJobjectWithKeyValues
:
userInfo
];
OffcnIMPushModel
*
IMModel
=
[
OffcnIMPushModel
mj_ZYJobjectWithKeyValues
:
userInfo
];
...
@@ -62,4 +68,19 @@
...
@@ -62,4 +68,19 @@
[[
OffcnIMZYJFMDBHandler
sharedInstance
]
insertChatInfoToFMDBWithModel
:
body
];
[[
OffcnIMZYJFMDBHandler
sharedInstance
]
insertChatInfoToFMDBWithModel
:
body
];
[[
OffcnIMZYJFMDBHandler
sharedInstance
]
chatlistCacheInfo
:
body
callback
:
nil
];
[[
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
@end
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.m
View file @
bdb38571
//
//
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
@property
(
nonatomic
,
strong
)
OIMCoreAdapter
*
adapter
;
@property
(
nonatomic
,
strong
)
OIMCoreAdapter
*
adapter
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
msgArr
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
msgArr
;
@property
(
nonatomic
)
UIBackgroundTaskIdentifier
backgroundTask
;
@end
@end
@implementation
OffcnIMSocketManager
@implementation
OffcnIMSocketManager
...
@@ -43,6 +45,26 @@ static OffcnIMSocketManager *socketManager;
...
@@ -43,6 +45,26 @@ static OffcnIMSocketManager *socketManager;
self
.
adapter
=
[
OIMCoreAdapter
sharedOIMCore
];
self
.
adapter
=
[
OIMCoreAdapter
sharedOIMCore
];
[
self
.
adapter
Initialize
];
[
self
.
adapter
Initialize
];
self
.
adapter
.
delegate
=
self
;
self
.
adapter
.
delegate
=
self
;
self
.
backgroundTask
=
UIBackgroundTaskInvalid
;
NSNotificationCenter
*
defaultCenter
=
[
NSNotificationCenter
defaultCenter
];
[
defaultCenter
addObserver
:
self
selector
:
@selector
(
appWillResignActive
)
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[
defaultCenter
addObserver
:
self
selector
:
@selector
(
appDidEnterBackground
)
name
:
UIApplicationDidEnterBackgroundNotification
object
:
nil
];
[
defaultCenter
addObserver
:
self
selector
:
@selector
(
appDidBecomeActive
)
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
}
}
return
self
;
return
self
;
}
}
...
@@ -170,4 +192,39 @@ static OffcnIMSocketManager *socketManager;
...
@@ -170,4 +192,39 @@ static OffcnIMSocketManager *socketManager;
}
}
}
}
}
}
-
(
void
)
appWillResignActive
{
// [self.sessionManager disconnectWithDisconnectHandler:nil];
}
-
(
void
)
appDidEnterBackground
{
// if (!self.sessionManager.requiresTearDown) {
// // we don't want to tear down session as it's already closed
// return;
// }
__weak
typeof
(
self
)
weakSelf
=
self
;
self
.
backgroundTask
=
[[
UIApplication
sharedApplication
]
beginBackgroundTaskWithExpirationHandler
:
^
{
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
[
strongSelf
endBackgroundTask
];
}];
}
-
(
void
)
appDidBecomeActive
{
// [self.sessionManager connectToLast:nil];
}
-
(
void
)
endBackgroundTask
{
if
(
self
.
backgroundTask
)
{
[[
UIApplication
sharedApplication
]
endBackgroundTask
:
self
.
backgroundTask
];
self
.
backgroundTask
=
UIBackgroundTaskInvalid
;
}
}
-
(
void
)
dealloc
{
NSNotificationCenter
*
defaultCenter
=
[
NSNotificationCenter
defaultCenter
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationDidEnterBackgroundNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
}
@end
@end
OffcnIMSDKiOS/ViewController.mm
View file @
bdb38571
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSocketManager.h"
#import "OffcnIMSocketManager.h"
#import "OffcnZYJTestDataStorageView.h"
#import "OffcnZYJTestDataStorageView.h"
#import "AppDelegate+OffcnIMPush.h"
@interface
ViewController
()
<
UINavigationControllerDelegate
,
UIImagePickerControllerDelegate
>
@interface
ViewController
()
<
UINavigationControllerDelegate
,
UIImagePickerControllerDelegate
>
...
@@ -92,6 +93,8 @@
...
@@ -92,6 +93,8 @@
}
else
{
}
else
{
msg
=
[
msg
stringByAppendingString
:
IMModel
.
body
.
msg
.
url
?
IMModel
.
body
.
msg
.
url
:
@"nil"
];
msg
=
[
msg
stringByAppendingString
:
IMModel
.
body
.
msg
.
url
?
IMModel
.
body
.
msg
.
url
:
@"nil"
];
}
}
[
AppDelegate
manualSendLocalNotificationWithModel
:
IMModel
];
// [weakSelf tipMessageWithTitle:@"收到消息" message:msg];
// [weakSelf tipMessageWithTitle:@"收到消息" message:msg];
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment