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
c877ffec
Commit
c877ffec
authored
Sep 14, 2020
by
zhangyunjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
启动SDK方法
parent
e3871fa2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
67 deletions
+58
-67
AppDelegate.m
OffcnIMSDKiOS/AppDelegate.m
+5
-42
AppDelegate+OffcnIMPush.h
...MSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.h
+1
-3
AppDelegate+OffcnIMPush.m
...MSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.m
+1
-16
OffcnIMSocketManager.h
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.h
+6
-1
OffcnIMSocketManager.mm
...nIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.mm
+41
-3
ViewController.m
OffcnIMSDKiOS/ViewController.m
+4
-2
No files found.
OffcnIMSDKiOS/AppDelegate.m
View file @
c877ffec
...
...
@@ -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
);
...
...
OffcnIMSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.h
View file @
c877ffec
//
//
...
...
@@ -22,8 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
//收到通知
+
(
void
)
didReceiveRemoteNotification
:(
NSDictionary
*
)
userInfo
;
//后台收到消息本地推送
+
(
void
)
manualSendLocalNotificationWithModel
:(
OffcnIMModel
*
)
model
;
@end
NS_ASSUME_NONNULL_END
...
...
OffcnIMSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.m
View file @
c877ffec
//
//
...
...
@@ -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
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.h
View file @
c877ffec
//
//
...
...
@@ -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
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.mm
View file @
c877ffec
//
//
...
...
@@ -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
OffcnIMSDKiOS/ViewController.m
View file @
c877ffec
...
...
@@ -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];
};
...
...
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