Skip to content

Commit

Permalink
Issue #106: MIKMIDIConnectionManager (optionally) saves its configura…
Browse files Browse the repository at this point in the history
…tion on application backgrounding/termination.
  • Loading branch information
Andrew Madsen committed Nov 14, 2015
1 parent e0ea4fc commit 8516f3f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Source/MIKMIDIConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#import "MIKMIDINoteOnCommand.h"
#import "MIKMIDINoteOffCommand.h"

#if TARGET_OS_IPHONE
#import <UIKit/UIApplication.h>
#else
#import <AppKit/NSApplication.h>
#endif

void *MIKMIDIConnectionManagerKVOContext = &MIKMIDIConnectionManagerKVOContext;

NSString * const MIKMIDIConnectionManagerConnectedDevicesKey = @"MIKMIDIConnectionManagerConnectedDevicesKey";
Expand Down Expand Up @@ -68,6 +74,13 @@ - (instancetype)initWithName:(NSString *)name delegate:(id<MIKMIDIConnectionMana
[nc addObserver:self selector:@selector(endpointWasPluggedIn:) name:MIKMIDIVirtualEndpointWasAddedNotification object:nil];
[nc addObserver:self selector:@selector(endpointWasUnplugged:) name:MIKMIDIVirtualEndpointWasRemovedNotification object:nil];

#if TARGET_OS_IPHONE
[nc addObserver:self selector:@selector(saveConfigurationOnApplicationLifecycleEvent:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[nc addObserver:self selector:@selector(saveConfigurationOnApplicationLifecycleEvent:) name:UIApplicationWillTerminateNotification object:nil];
#else
[nc addObserver:self selector:@selector(saveConfigurationOnApplicationLifecycleEvent:) name:NSApplicationWillTerminateNotification object:nil];
#endif

[self updateAvailableDevices];
[self scanAndConnectToInitialAvailableDevices];
}
Expand Down Expand Up @@ -462,6 +475,13 @@ - (void)endpointWasUnplugged:(NSNotification *)notification
if (unpluggedDevice) [self internalDisconnectFromDevice:unpluggedDevice];
}

- (void)saveConfigurationOnApplicationLifecycleEvent:(NSNotification *)notification
{
if (self.automaticallySavesConfiguration) {
[self saveConfiguration];
}
}

#pragma mark - KVO

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
Expand Down

0 comments on commit 8516f3f

Please sign in to comment.