Commit 12769036 by zhangyunjie

推送

parent 5d46688b
......@@ -9,6 +9,7 @@
#import "AppDelegate.h"
#import "ViewController.h"
#import "OffcnIMSDKiOS.h"
#import "OffcnIMSocketManager.h"
@interface AppDelegate ()
......@@ -56,12 +57,22 @@
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if ([OffcnIMSocketManager defaultService].IMConnectStatus != OffcnIMConnectStatusSuccess) {
//建立连接
NSString *paramStr = @"{\"server_ip\":\"192.168.43.141\", \"server_port\":1026, \"account_id\":\"ce0819db8391f1e7258a71cc9e2c3235\",\"app_id\":\"offcn_live\", \"device_type\":\"ios\", \"token\":\"fadbce3f4929b6bdee0617fee34e32ae\", \"session_id\":\"123\", \"connection_type\":\"websocket\", \"tls\":\"disable\"}";
[[OffcnIMSocketManager defaultService] connectIMServerWithParam:paramStr];
}
//进入前台,清除推送角标
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[application cancelAllLocalNotifications];
// [JPUSHService setBadge:0];
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
//断开连接
[[OffcnIMSocketManager defaultService] disConnectIMServer];
}
......@@ -131,6 +142,15 @@
NSLog(@"注册失败%@",error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
// [self pushNotificationDefaultController];
}
// Required, iOS 7 Support
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"接收到远程推送通知 ---- %@", userInfo);
......
//
//
......@@ -26,6 +26,8 @@ typedef void(^OffcnIMReceiveConnectStatus)(OffcnIMConnectStatus status,NSString
@interface OffcnIMSocketManager : NSObject
@property (nonatomic, assign) OffcnIMConnectStatus IMConnectStatus;
@property (nonatomic, copy) OffcnIMConnectReceiveMessage connectReceiveMessage;
@property (nonatomic, copy) OffcnIMReceiveConnectStatus connectStatus;
......
//
//
......@@ -104,12 +104,16 @@ static OffcnIMSocketManager *socketManager;
if (self.connectStatus) {
NSString *message = [NSString stringWithUTF8String:context];
if (code == 0) {
self.IMConnectStatus = OffcnIMConnectStatusSuccess;
self.connectStatus(OffcnIMConnectStatusSuccess,message);
}else if (code == 1){
self.IMConnectStatus = OffcnIMConnectStatusFail;
self.connectStatus(OffcnIMConnectStatusFail,message);
}else if (code == 2){
self.IMConnectStatus = OffcnIMConnectStatusBreak;
self.connectStatus(OffcnIMConnectStatusBreak,message);
}else if (code == 3){
self.IMConnectStatus = OffcnIMConnectStatusDisConnectOK;
self.connectStatus(OffcnIMConnectStatusDisConnectOK,message);
}
}
......
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