Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve available devices after app did become active #210

Merged
merged 3 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Framework/MIKMIDI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
9DF99E7A1831841A004EE5F4 /* MIKMIDICommandThrottler.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF99E781831841A004EE5F4 /* MIKMIDICommandThrottler.m */; };
9DF99E7D18318D44004EE5F4 /* MIKMIDIPrivateUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 9DF99E7B18318D44004EE5F4 /* MIKMIDIPrivateUtilities.h */; };
9DF99E7E18318D44004EE5F4 /* MIKMIDIPrivateUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DF99E7C18318D44004EE5F4 /* MIKMIDIPrivateUtilities.m */; };
D9E590031FA20E8600166B5C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9E590021FA20E8600166B5C /* UIKit.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -487,6 +488,7 @@
9DF99E7B18318D44004EE5F4 /* MIKMIDIPrivateUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDIPrivateUtilities.h; sourceTree = "<group>"; };
9DF99E7C18318D44004EE5F4 /* MIKMIDIPrivateUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIPrivateUtilities.m; sourceTree = "<group>"; };
9DFDC2B61820305C00C4C66D /* MIKMIDIPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDIPrivate.h; sourceTree = "<group>"; };
D9E590021FA20E8600166B5C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -512,6 +514,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D9E590031FA20E8600166B5C /* UIKit.framework in Frameworks */,
9DAF8B8A1A7B028B00F46528 /* libxml2.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -599,6 +602,7 @@
9D74EEA717A7129300BEE89F /* Frameworks */ = {
isa = PBXGroup;
children = (
D9E590021FA20E8600166B5C /* UIKit.framework */,
9DAF8B861A7B01AA00F46528 /* libxml2.2.dylib */,
9DAF8B841A7B019900F46528 /* libxml2.dylib */,
9DE259E719A7B50600DA93E9 /* AudioToolbox.framework */,
Expand Down
24 changes: 23 additions & 1 deletion Source/MIKMIDIDeviceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#import "MIKMIDIClientSourceEndpoint.h"
#import "MIKMIDIErrors.h"

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

#if !__has_feature(objc_arc)
#error MIKMIDIDeviceManager.m must be compiled with ARC. Either turn on ARC for the project or set the -fobjc-arc flag for MIKMIDIDeviceManager.m in the Build Phases for this target
#endif
Expand Down Expand Up @@ -73,6 +77,12 @@ - (id)init
[self createClient];
[self retrieveAvailableDevices];
[self retrieveVirtualEndpoints];

#if TARGET_OS_IPHONE
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(appDidBecomeActiveNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
#endif

}
return self;
}
Expand All @@ -87,6 +97,11 @@ - (id)copyWithZone:(NSZone *)zone
return self;
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Public

- (nullable id)connectDevice:(MIKMIDIDevice *)device error:(NSError **)error eventHandler:(MIKMIDIEventHandlerBlock)eventHandler
Expand Down Expand Up @@ -184,6 +199,13 @@ - (void)retrieveVirtualEndpoints
self.internalVirtualDestinations = destinations;
}

#pragma mark - Notifications

- (void)appDidBecomeActiveNotification:(NSNotification *)notification
{
[self retrieveAvailableDevices];
}

#pragma mark - Callbacks

- (void)handleMIDIObjectPropertyChangeNotification:(MIDIObjectPropertyChangeNotification *)notification
Expand Down Expand Up @@ -456,4 +478,4 @@ - (void)disconnectInput:(MIKMIDISourceEndpoint *)endpoint forConnectionToken:(id
[self disconnectConnectionForToken:connectionToken];
}

@end
@end