Browse Source

iOS: Added memory warning callbacks

tags/2021-05-28
Tom Poole 7 years ago
parent
commit
8c0f0815f0
5 changed files with 52 additions and 15 deletions
  1. +14
    -6
      modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm
  2. +10
    -0
      modules/juce_audio_processors/processors/juce_AudioProcessor.h
  3. +10
    -0
      modules/juce_events/messages/juce_ApplicationBase.h
  4. +6
    -6
      modules/juce_events/native/juce_mac_MessageManager.mm
  5. +12
    -3
      modules/juce_gui_basics/native/juce_ios_Windowing.mm

+ 14
- 6
modules/juce_audio_plugin_client/AU/juce_AUv3_Wrapper.mm View File

@@ -1556,6 +1556,13 @@ public:
}
}
void didReceiveMemoryWarning()
{
if (processorHolder != nullptr)
if (auto* processor = processorHolder->get())
processor->memoryWarningReceived();
}
CGSize getPreferredContentSize() const
{
return CGSizeMake (static_cast<float> (preferredSize.getWidth()),
@@ -1634,11 +1641,12 @@ private:
ScopedPointer<JuceAUViewController> cpp;
}
- (instancetype) initWithNibName: (nullable NSString*) nib bundle: (nullable NSBundle*) bndl { self = [super initWithNibName: nib bundle: bndl]; cpp = new JuceAUViewController (self); return self;}
- (void) loadView { cpp->loadView(); }
- (AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error { return cpp->createAudioUnit (desc, error); }
- (CGSize) preferredContentSize { return cpp->getPreferredContentSize(); }
- (void)viewDidLayoutSubviews { return cpp->viewDidLayoutSubviews(); }
- (instancetype) initWithNibName: (nullable NSString*) nib bundle: (nullable NSBundle*) bndl { self = [super initWithNibName: nib bundle: bndl]; cpp = new JuceAUViewController (self); return self; }
- (void) loadView { cpp->loadView(); }
- (AUAudioUnit *) createAudioUnitWithComponentDescription: (AudioComponentDescription) desc error: (NSError **) error { return cpp->createAudioUnit (desc, error); }
- (CGSize) preferredContentSize { return cpp->getPreferredContentSize(); }
- (void) viewDidLayoutSubviews { cpp->viewDidLayoutSubviews(); }
- (void) didReceiveMemoryWarning { cpp->didReceiveMemoryWarning(); }
@end
//==============================================================================
@@ -1646,7 +1654,7 @@ private:
bool JUCE_CALLTYPE juce_isInterAppAudioConnected() { return false; }
void JUCE_CALLTYPE juce_switchToHostApplication() {}
#if JUCE_MODULE_AVAILABLE_juce_gui_basics
Image JUCE_CALLTYPE juce_getIAAHostIcon (int) { return Image(); }
Image JUCE_CALLTYPE juce_getIAAHostIcon (int) { return {}; }
#endif
#endif


+ 10
- 0
modules/juce_audio_processors/processors/juce_AudioProcessor.h View File

@@ -129,6 +129,16 @@ public:
*/
virtual void releaseResources() = 0;
/** Called by the host to indicate that you should reduce your memory footprint.
You should override this method to free up some memory gracefully, if possible,
otherwise the host may forcibly unload your AudioProcessor.
At the moment this method is only called when your AudioProcessor is an AUv3
plug-in running on iOS.
*/
virtual void memoryWarningReceived() { jassertfalse; }
/** Renders the next block.
When this method is called, the buffer contains a number of channels which is


+ 10
- 0
modules/juce_events/messages/juce_ApplicationBase.h View File

@@ -188,6 +188,16 @@ public:
const String& sourceFilename,
int lineNumber) = 0;
/** Called by the operating system to indicate that you should reduce your memory
footprint.
You should override this method to free up some memory gracefully, if possible,
otherwise the host may forcibly kill your app.
At the moment this method is only called on iOS.
*/
virtual void memoryWarningReceived() { jassertfalse; }
//==============================================================================
/** Override this method to be informed when the back button is pressed on a device.
This is currently only implemented on Android devices.


+ 6
- 6
modules/juce_events/native/juce_mac_MessageManager.mm View File

@@ -116,7 +116,7 @@ private:
addMethod (@selector (mainMenuTrackingEnded:), mainMenuTrackingEnded, "v@:@");
addMethod (@selector (dummyMethod), dummyMethod, "v@:");
#if JUCE_PUSH_NOTIFICATIONS
#if JUCE_PUSH_NOTIFICATIONS
//==============================================================================
addIvar<NSObject<NSApplicationDelegate, NSUserNotificationCenterDelegate>*> ("pushNotificationsDelegate");
@@ -125,7 +125,7 @@ private:
addMethod (@selector (application:didRegisterForRemoteNotificationsWithDeviceToken:), registeredForRemoteNotifications, "v@:@@");
addMethod (@selector (application:didFailToRegisterForRemoteNotificationsWithError:), failedToRegisterForRemoteNotifications, "v@:@@");
addMethod (@selector (application:didReceiveRemoteNotification:), didReceiveRemoteNotification, "v@:@@");
#endif
#endif
registerClass();
}
@@ -139,7 +139,7 @@ private:
andEventID: kAEGetURL];
}
#if JUCE_PUSH_NOTIFICATIONS
#if JUCE_PUSH_NOTIFICATIONS
static void applicationDidFinishLaunching (id self, SEL, NSNotification* notification)
{
if (notification.userInfo != nil)
@@ -150,7 +150,7 @@ private:
didReceiveRemoteNotification (self, nil, [NSApplication sharedApplication], userNotification.userInfo);
}
}
#endif
#endif
static NSApplicationTerminateReply applicationShouldTerminate (id /*self*/, SEL, NSApplication*)
{
@@ -241,7 +241,7 @@ private:
return s;
}
#if JUCE_PUSH_NOTIFICATIONS
#if JUCE_PUSH_NOTIFICATIONS
//==============================================================================
static void setPushNotificationsDelegate (id self, SEL, NSObject<NSApplicationDelegate, NSUserNotificationCenterDelegate>* delegate)
{
@@ -306,7 +306,7 @@ private:
[invocation invoke];
}
}
#endif
#endif
};
};


+ 12
- 3
modules/juce_gui_basics/native/juce_ios_Windowing.mm View File

@@ -57,6 +57,7 @@ namespace juce
- (void) applicationWillResignActive: (UIApplication*) application;
- (void) application: (UIApplication*) application handleEventsForBackgroundURLSession: (NSString*) identifier
completionHandler: (void (^)(void)) completionHandler;
- (void) applicationDidReceiveMemoryWarning: (UIApplication *) application;
#if JUCE_PUSH_NOTIFICATIONS
- (void) application: (UIApplication*) application didRegisterUserNotificationSettings: (UIUserNotificationSettings*) notificationSettings;
- (void) application: (UIApplication*) application didRegisterForRemoteNotificationsWithDeviceToken: (NSData*) deviceToken;
@@ -92,9 +93,9 @@ namespace juce
self = [super init];
appSuspendTask = UIBackgroundTaskInvalid;
#if JUCE_PUSH_NOTIFICATIONS && defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#if JUCE_PUSH_NOTIFICATIONS && defined (__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
#endif
#endif
return self;
}
@@ -104,7 +105,7 @@ namespace juce
ignoreUnused (application);
initialiseJuce_GUI();
if (JUCEApplicationBase* app = JUCEApplicationBase::createInstance())
if (auto* app = JUCEApplicationBase::createInstance())
{
if (! app->initialiseApp())
exit (app->shutdownApp());
@@ -174,6 +175,14 @@ namespace juce
completionHandler();
}
- (void) applicationDidReceiveMemoryWarning: (UIApplication*) application
{
ignoreUnused (application);
if (auto* app = JUCEApplicationBase::getInstance())
app->memoryWarningReceived();
}
- (void) setPushNotificationsDelegateToUse: (NSObject*) delegate
{
_pushNotificationsDelegate = delegate;


Loading…
Cancel
Save