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
Hide 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 @@
...
@@ -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.
// 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
{
-
(
void
)
applicationDidBecomeActive
:(
UIApplication
*
)
application
{
if
([
OffcnIMSocketManager
defaultService
].
IMConnectStatus
!=
OffcnIMConnectStatusSuccess
)
{
//建立连接
// [[OffcnIMSocketManager defaultService] connectIMServerWithAccount_id:@"ce0819db8391f1e7258a71cc9e2c3235" token:@"fadbce3f4929b6bdee0617fee34e32ae"];
}
//进入前台,清除推送角标
//进入前台,清除推送角标
[
UIApplication
sharedApplication
].
applicationIconBadgeNumber
=
0
;
[
UIApplication
sharedApplication
].
applicationIconBadgeNumber
=
0
;
...
@@ -73,22 +72,12 @@
...
@@ -73,22 +72,12 @@
// [JPUSHService setBadge:0];
// [JPUSHService setBadge:0];
}
}
-
(
void
)
applicationWillTerminate
:(
UIApplication
*
)
application
{
//断开连接
[[
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
{
}
}
/**
//远程推送注册成功
* 远程推送注册成功
*
* @param deviceToken deviceToken
*/
-
(
void
)
application
:(
UIApplication
*
)
application
didRegisterForRemoteNotificationsWithDeviceToken
:(
NSData
*
)
deviceToken
{
-
(
void
)
application
:(
UIApplication
*
)
application
didRegisterForRemoteNotificationsWithDeviceToken
:(
NSData
*
)
deviceToken
{
// 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
);
...
@@ -103,10 +92,7 @@
...
@@ -103,10 +92,7 @@
// applicationIconBadgeNumber
// applicationIconBadgeNumber
}
}
/**
//注册失败
* 注册失败
*
*/
-
(
void
)
application
:(
UIApplication
*
)
application
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
{
-
(
void
)
application
:(
UIApplication
*
)
application
didFailToRegisterForRemoteNotificationsWithError
:(
NSError
*
)
error
{
NSLog
(
@"注册失败 ---- %@"
,
error
);
NSLog
(
@"注册失败 ---- %@"
,
error
);
...
@@ -133,33 +119,10 @@
...
@@ -133,33 +119,10 @@
NSLog
(
@"接收到远程推送通知 ---- %@"
,
userInfo
);
NSLog
(
@"接收到远程推送通知 ---- %@"
,
userInfo
);
[
AppDelegate
didReceiveRemoteNotification
:
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形式呈现
//将推送消息以alert形式呈现
NSString
*
message
=
[[
userInfo
objectForKey
:
@"aps"
]
objectForKey
:
@"alert"
];
NSString
*
message
=
[[
userInfo
objectForKey
:
@"aps"
]
objectForKey
:
@"alert"
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"提示"
message
:
message
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"确定"
,
nil
];
UIAlertView
*
alert
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"提示"
message
:
message
delegate
:
self
cancelButtonTitle
:
@"取消"
otherButtonTitles
:
@"确定"
,
nil
];
[
alert
show
];
[
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
{
-
(
void
)
application
:(
UIApplication
*
)
application
didReceiveLocalNotification
:(
UILocalNotification
*
)
notification
{
NSLog
(
@"接收到本地推送通知 ---- %@"
,
notification
.
userInfo
);
NSLog
(
@"接收到本地推送通知 ---- %@"
,
notification
.
userInfo
);
...
...
OffcnIMSDKiOS/ExposedInterface-(外放接口)/AppDelegate+OffcnIMPush.h
View file @
c877ffec
//
//
...
@@ -22,8 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
...
@@ -22,8 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
//收到通知
//收到通知
+
(
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 @
c877ffec
//
//
...
@@ -83,19 +83,4 @@
...
@@ -83,19 +83,4 @@
[[
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.h
View file @
c877ffec
//
//
...
@@ -28,6 +28,8 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
...
@@ -28,6 +28,8 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
@interface
OffcnIMSocketManager
:
NSObject
@interface
OffcnIMSocketManager
:
NSObject
@property
(
nonatomic
,
copy
)
NSString
*
msg_fromId
;
//发送消息的用户id
@property
(
nonatomic
,
copy
)
NSString
*
msg_fromId
;
//发送消息的用户id
@property
(
nonatomic
,
copy
)
NSString
*
token
;
//发送消息的用户token
@property
(
nonatomic
,
assign
)
OffcnIMConnectStatus
IMConnectStatus
;
@property
(
nonatomic
,
assign
)
OffcnIMConnectStatus
IMConnectStatus
;
...
@@ -44,6 +46,9 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
...
@@ -44,6 +46,9 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
//断开连接
//断开连接
-
(
void
)
disConnectIMServer
;
-
(
void
)
disConnectIMServer
;
//后台收到消息本地推送
-
(
void
)
manualSendLocalNotificationWithModel
:(
OffcnIMModel
*
)
model
;
@end
@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
OffcnIMSDKiOS/ExposedInterface-(外放接口)/OffcnIMSocketManager.mm
View file @
c877ffec
//
//
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
@property
(
nonatomic
,
strong
)
OIMCoreAdapter
*
adapter
;
@property
(
nonatomic
,
strong
)
OIMCoreAdapter
*
adapter
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
msgArr
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
msgArr
;
@property
(
nonatomic
,
assign
)
BOOL
isActive
;
@property
(
nonatomic
)
UIBackgroundTaskIdentifier
backgroundTask
;
@property
(
nonatomic
)
UIBackgroundTaskIdentifier
backgroundTask
;
@end
@end
...
@@ -46,7 +48,7 @@ static OffcnIMSocketManager *socketManager;
...
@@ -46,7 +48,7 @@ static OffcnIMSocketManager *socketManager;
[
self
.
adapter
Initialize
];
[
self
.
adapter
Initialize
];
self
.
adapter
.
delegate
=
self
;
self
.
adapter
.
delegate
=
self
;
self
.
isActive
=
YES
;
self
.
backgroundTask
=
UIBackgroundTaskInvalid
;
self
.
backgroundTask
=
UIBackgroundTaskInvalid
;
NSNotificationCenter
*
defaultCenter
=
[
NSNotificationCenter
defaultCenter
];
NSNotificationCenter
*
defaultCenter
=
[
NSNotificationCenter
defaultCenter
];
...
@@ -65,6 +67,11 @@ static OffcnIMSocketManager *socketManager;
...
@@ -65,6 +67,11 @@ static OffcnIMSocketManager *socketManager;
selector
:
@selector
(
appDidBecomeActive
)
selector
:
@selector
(
appDidBecomeActive
)
name
:
UIApplicationDidBecomeActiveNotification
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
object
:
nil
];
[
defaultCenter
addObserver
:
self
selector
:
@selector
(
appWillTerminateNotification
)
name
:
UIApplicationWillTerminateNotification
object
:
nil
];
}
}
return
self
;
return
self
;
}
}
...
@@ -84,6 +91,7 @@ static OffcnIMSocketManager *socketManager;
...
@@ -84,6 +91,7 @@ static OffcnIMSocketManager *socketManager;
// tls = ["disable", "enable"]
// tls = ["disable", "enable"]
self
.
msg_fromId
=
account_id
;
self
.
msg_fromId
=
account_id
;
self
.
token
=
token
;
NSMutableDictionary
*
dic
=
[
NSMutableDictionary
dictionary
];
NSMutableDictionary
*
dic
=
[
NSMutableDictionary
dictionary
];
[
dic
setObjectOnSafe
:
@"39.102.42.185"
forKey
:
@"server_ip"
];
[
dic
setObjectOnSafe
:
@"39.102.42.185"
forKey
:
@"server_ip"
];
...
@@ -204,6 +212,23 @@ static OffcnIMSocketManager *socketManager;
...
@@ -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
{
-
(
void
)
appWillResignActive
{
// [self.sessionManager disconnectWithDisconnectHandler:nil];
// [self.sessionManager disconnectWithDisconnectHandler:nil];
...
@@ -215,6 +240,8 @@ static OffcnIMSocketManager *socketManager;
...
@@ -215,6 +240,8 @@ static OffcnIMSocketManager *socketManager;
// return;
// return;
// }
// }
self
.
isActive
=
NO
;
__weak
typeof
(
self
)
weakSelf
=
self
;
__weak
typeof
(
self
)
weakSelf
=
self
;
self
.
backgroundTask
=
[[
UIApplication
sharedApplication
]
beginBackgroundTaskWithExpirationHandler
:
^
{
self
.
backgroundTask
=
[[
UIApplication
sharedApplication
]
beginBackgroundTaskWithExpirationHandler
:
^
{
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
__strong
typeof
(
weakSelf
)
strongSelf
=
weakSelf
;
...
@@ -223,7 +250,17 @@ static OffcnIMSocketManager *socketManager;
...
@@ -223,7 +250,17 @@ static OffcnIMSocketManager *socketManager;
}
}
-
(
void
)
appDidBecomeActive
{
-
(
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
{
-
(
void
)
endBackgroundTask
{
...
@@ -237,5 +274,6 @@ static OffcnIMSocketManager *socketManager;
...
@@ -237,5 +274,6 @@ static OffcnIMSocketManager *socketManager;
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationWillResignActiveNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationDidEnterBackgroundNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationDidEnterBackgroundNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationDidBecomeActiveNotification
object
:
nil
];
[
defaultCenter
removeObserver
:
self
name
:
UIApplicationWillTerminateNotification
object
:
nil
];
}
}
@end
@end
OffcnIMSDKiOS/ViewController.m
View file @
c877ffec
...
@@ -9,9 +9,10 @@
...
@@ -9,9 +9,10 @@
#import "ViewController.h"
#import "ViewController.h"
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSocketManager.h"
#import "OffcnIMSocketManager.h"
#import "OffcnZYJTestDataStorageView.h"
#import "AppDelegate+OffcnIMPush.h"
#import "AppDelegate+OffcnIMPush.h"
#import "OffcnZYJTestDataStorageView.h"
@interface
ViewController
()
<
UINavigationControllerDelegate
,
UIImagePickerControllerDelegate
>
@interface
ViewController
()
<
UINavigationControllerDelegate
,
UIImagePickerControllerDelegate
>
@property
(
weak
,
nonatomic
)
IBOutlet
UIButton
*
changeEnvironmentBtn
;
@property
(
weak
,
nonatomic
)
IBOutlet
UIButton
*
changeEnvironmentBtn
;
...
@@ -94,7 +95,8 @@
...
@@ -94,7 +95,8 @@
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
];
//进入后台正常连接socket,使用此方法本地推送接受到的消息
[[
OffcnIMSocketManager
defaultService
]
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