• 大小: 329KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: 其他
  • 标签: ios  

资源简介

oc开发,服务器端启动mqtt服务端,手机端使用mqtt客户端,动态获取推送消息,参考demo

资源截图

代码片段和文件信息

//
//  ForegroundReconnection.m
//  MQTTClient
//
//  Created by Josip Cavar on 22/08/2017.
//  Copyright © 2017 Christoph Krey. All rights reserved.
//

#import “ForegroundReconnection.h“

#if TARGET_OS_IPHONE == 1
#import “MQTTSessionManager.h“
#import 
@interface ForegroundReconnection ()

@property (nonatomic) UIBackgroundTaskIdentifier backgroundTask;

@end

@implementation ForegroundReconnection

- (instancetype)initWithMQTTSessionManager:(MQTTSessionManager *)manager {
    self = [super init];
    self.sessionManager = manager;
    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;
}

- (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];
}

- (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;
    }
}

@end

#endif

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\
     文件         220  2018-02-16 09:43  MQTT-Client-framework-master\.gitignore
     文件         317  2018-02-16 09:43  MQTT-Client-framework-master\.travis.yml
     文件       10497  2018-02-16 09:43  MQTT-Client-framework-master\CHANGELOG.md
     文件       12922  2018-02-16 09:43  MQTT-Client-framework-master\LICENSE
     文件        4506  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient.podspec
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\
     文件      135441  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\project.pbxproj
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\project.xcworkspace\
     文件         155  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\project.xcworkspace\contents.xcworkspacedata
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\xcshareddata\
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\xcshareddata\xcschemes\
     文件        3746  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\xcshareddata\xcschemes\MQTTClientiOS.xcscheme
     文件        3758  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\xcshareddata\xcschemes\MQTTClientmacOS.xcscheme
     文件        3752  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcodeproj\xcshareddata\xcschemes\MQTTClienttvOS.xcscheme
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcworkspace\
     文件         228  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcworkspace\contents.xcworkspacedata
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcworkspace\xcshareddata\
     文件        1677  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient.xcworkspace\xcshareddata\MQTTClient.xcscmblueprint
     目录           0  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\
     文件      101124  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\Doxyfile
     文件         444  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\ForegroundReconnection.h
     文件        2576  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\ForegroundReconnection.m
     文件         496  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\GCDTimer.h
     文件        1691  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\GCDTimer.m
     文件        1009  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\MQTTCFSocketDecoder.h
     文件        2710  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\MQTTCFSocketDecoder.m
     文件         957  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\MQTTCFSocketEncoder.h
     文件        3580  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\MQTTCFSocketEncoder.m
     文件        2522  2018-02-16 09:43  MQTT-Client-framework-master\MQTTClient\MQTTClient\MQTTCFSocketTransport.h
............此处省略203个文件信息

评论

共有 条评论