File tree Expand file tree Collapse file tree
dConnectDevicePlugin/dConnectDeviceLinking/dConnectDeviceLinking/Classes
dConnectSDK/dConnectSDKForIOS/DConnectSDK/Classes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010#import " DPLinkingDevicePlugin.h"
1111#import " DPLinkingServiceDiscoveryProfile.h"
1212#import " DPLinkingSystemProfile.h"
13+ #import " DPLinkingDeviceManager.h"
1314
1415@implementation DPLinkingDevicePlugin
1516
@@ -24,9 +25,25 @@ - (id) init
2425
2526 [self addProfile: [[DPLinkingServiceDiscoveryProfile alloc ] initWithServiceProvider: self .serviceProvider]];
2627 [self addProfile: [DPLinkingSystemProfile systemProfileWithVersion: @" 1.0" ]];
28+
29+ __weak typeof (self) weakSelf = self;
30+
31+ dispatch_async (dispatch_get_main_queue (), ^{
32+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter ];
33+ UIApplication *application = [UIApplication sharedApplication ];
34+ [notificationCenter addObserver: weakSelf
35+ selector: @selector (enterForeground )
36+ name: UIApplicationWillEnterForegroundNotification
37+ object: application];
38+ });
2739 }
2840 return self;
2941}
42+
43+ - (void ) enterForeground {
44+ [[DPLinkingDeviceManager sharedInstance ] restart ];
45+ }
46+
3047#pragma mark - DevicePlugin's icon image
3148
3249- (NSString *)iconFilePath : (BOOL )isOnline
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ - (id) initWithCoder:(NSCoder *)coder {
3434 self.vibrationOffPatternId = [[coder decodeObjectForKey: kVibrationOffPatternId ] intValue ];
3535 self.connectFlag = [[coder decodeObjectForKey: kConnectFlag ] boolValue ];
3636 self.temperatureType = DCMTemperatureProfileEnumCelsius;
37+ self.online = NO ;
3738
3839 DCLogInfo (@" LDPDevice" );
3940 DCLogInfo (@" name: %@ " , self.name );
Original file line number Diff line number Diff line change 7272- (void ) stopScan ;
7373- (BOOL ) isStartScan ;
7474
75+ - (void ) restart ;
76+
7577- (NSArray *) getDPLinkingDevices ;
7678
7779- (DPLinkingDevice *) createDPLinkingDevice : (CBPeripheral *)peripheral ;
Original file line number Diff line number Diff line change @@ -102,6 +102,10 @@ - (BOOL) isStartScan {
102102 return [[BLEConnecter sharedInstance ] isScanning ];
103103}
104104
105+ - (void ) restart {
106+ [self startScanWithTimeout: 20 ];
107+ }
108+
105109- (DPLinkingDevice *) findDPLinkingDeviceByPeripheral : (CBPeripheral *)peripheral {
106110 __block DPLinkingDevice *result = nil ;
107111 [self .devices enumerateObjectsUsingBlock: ^(DPLinkingDevice *obj, NSUInteger idx, BOOL *stop) {
@@ -635,6 +639,7 @@ - (void) removeConnectDelegate:(id<DPLinkingDeviceConnectDelegate>)delegate {
635639
636640- (void ) startScanWithTimeout : (NSTimeInterval )timeout {
637641 if ([BLEConnecter sharedInstance ].canDiscovery ) {
642+ DCLogInfo (@" DPLinkingDeviceManager::startScanWithTimeout" );
638643 [DPLinkingUtil asyncAfterDelay: timeout block: ^{
639644 DCLogWarn (@" Timeout." );
640645 _initFlag = NO ;
@@ -836,7 +841,7 @@ - (void) didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSD
836841 [self stopScan ];
837842 [self connectDPLinkingDevice: device];
838843 } else if (_initFlag) {
839- if (device.connectFlag ) {
844+ if (device.connectFlag && !device. online ) {
840845 [self connectDPLinkingDevice: device];
841846 }
842847 }
Original file line number Diff line number Diff line change @@ -231,9 +231,6 @@ - (BOOL) start {
231231
232232 _requestQueue = dispatch_queue_create (" org.deviceconnect.manager.queue.request" , DISPATCH_QUEUE_SERIAL);
233233
234- // デバイスプラグインの検索
235- [self .mDeviceManager searchDevicePlugin ];
236-
237234 _webServer = [DConnectServerManager new ];
238235 _webServer.settings = self.settings ;
239236
@@ -249,7 +246,6 @@ - (void) stop {
249246 return ;
250247 }
251248 self.mStartFlag = NO ;
252-
253249 [_webServer stopServer ];
254250}
255251
@@ -451,6 +447,9 @@ - (id) init {
451447 self.mEventSessionTable = [DConnectEventSessionTable new ];
452448 self.mEventBroker = [[DConnectEventBroker alloc ] initWithContext: self table: self .mEventSessionTable localOAuth: self .mLocalOAuth pluginManager: self .mDeviceManager delegate: self .delegate];
453449
450+ // デバイスプラグインの検索
451+ [self .mDeviceManager searchDevicePlugin ];
452+
454453 // プロファイルの追加
455454 [self addProfile: [DConnectManagerServiceDiscoveryProfile new ]];
456455 [self addProfile: [DConnectManagerSystemProfile new ]];
You can’t perform that action at this time.
0 commit comments