| @@ -124,20 +124,27 @@ void LookAndFeel::playAlertSound() | |||
| //============================================================================== | |||
| class iOSMessageBox; | |||
| } // (juce namespace) | |||
| #if defined (__IPHONE_8_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 | |||
| #define JUCE_USE_NEW_IOS_ALERTWINDOW 1 | |||
| #endif | |||
| @interface JuceAlertBoxDelegate : NSObject <UIAlertViewDelegate> | |||
| { | |||
| @public | |||
| iOSMessageBox* owner; | |||
| } | |||
| #if ! JUCE_USE_NEW_IOS_ALERTWINDOW | |||
| } // (juce namespace) | |||
| - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex; | |||
| @interface JuceAlertBoxDelegate : NSObject <UIAlertViewDelegate> | |||
| { | |||
| @public | |||
| iOSMessageBox* owner; | |||
| } | |||
| @end | |||
| - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex; | |||
| @end | |||
| namespace juce | |||
| { | |||
| #endif | |||
| namespace juce | |||
| { | |||
| class iOSMessageBox | |||
| { | |||
| @@ -145,9 +152,30 @@ public: | |||
| iOSMessageBox (const String& title, const String& message, | |||
| NSString* button1, NSString* button2, NSString* button3, | |||
| ModalComponentManager::Callback* cb, const bool async) | |||
| : result (0), resultReceived (false), delegate (nil), alert (nil), | |||
| callback (cb), isYesNo (button3 != nil), isAsync (async) | |||
| : result (0), resultReceived (false), callback (cb), isAsync (async) | |||
| { | |||
| #if JUCE_USE_NEW_IOS_ALERTWINDOW | |||
| if (currentlyFocusedPeer != nullptr) | |||
| { | |||
| UIAlertController* alert = [UIAlertController alertControllerWithTitle: juceStringToNS (title) | |||
| message: juceStringToNS (message) | |||
| preferredStyle: UIAlertControllerStyleAlert]; | |||
| addButton (alert, button1, 0); | |||
| addButton (alert, button2, 1); | |||
| addButton (alert, button3, 2); | |||
| [currentlyFocusedPeer->controller presentViewController: alert | |||
| animated: YES | |||
| completion: nil]; | |||
| } | |||
| else | |||
| { | |||
| // Since iOS8, alert windows need to be associated with a window, so you need to | |||
| // have at least one window on screen when you use this | |||
| jassertfalse; | |||
| } | |||
| #else | |||
| delegate = [[JuceAlertBoxDelegate alloc] init]; | |||
| delegate->owner = this; | |||
| @@ -158,12 +186,15 @@ public: | |||
| otherButtonTitles: button2, button3, nil]; | |||
| [alert retain]; | |||
| [alert show]; | |||
| #endif | |||
| } | |||
| ~iOSMessageBox() | |||
| { | |||
| #if ! JUCE_USE_NEW_IOS_ALERTWINDOW | |||
| [alert release]; | |||
| [delegate release]; | |||
| #endif | |||
| } | |||
| int getResult() | |||
| @@ -172,7 +203,11 @@ public: | |||
| JUCE_AUTORELEASEPOOL | |||
| { | |||
| #if JUCE_USE_NEW_IOS_ALERTWINDOW | |||
| while (! resultReceived) | |||
| #else | |||
| while (! (alert.hidden || resultReceived)) | |||
| #endif | |||
| [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]]; | |||
| } | |||
| @@ -194,28 +229,43 @@ public: | |||
| private: | |||
| int result; | |||
| bool resultReceived; | |||
| JuceAlertBoxDelegate* delegate; | |||
| UIAlertView* alert; | |||
| ScopedPointer<ModalComponentManager::Callback> callback; | |||
| const bool isYesNo, isAsync; | |||
| const bool isAsync; | |||
| #if JUCE_USE_NEW_IOS_ALERTWINDOW | |||
| void addButton (UIAlertController* alert, NSString* text, int index) | |||
| { | |||
| if (text != nil) | |||
| [alert addAction: [UIAlertAction actionWithTitle: text | |||
| style: UIAlertActionStyleDefault | |||
| handler: ^(UIAlertAction* action) { this->buttonClicked (index); }]]; | |||
| } | |||
| #else | |||
| UIAlertView* alert; | |||
| JuceAlertBoxDelegate* delegate; | |||
| #endif | |||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iOSMessageBox) | |||
| }; | |||
| } // (juce namespace) | |||
| @implementation JuceAlertBoxDelegate | |||
| #if ! JUCE_USE_NEW_IOS_ALERTWINDOW | |||
| } // (juce namespace) | |||
| - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex | |||
| { | |||
| owner->buttonClicked ((int) buttonIndex); | |||
| alertView.hidden = true; | |||
| } | |||
| @implementation JuceAlertBoxDelegate | |||
| @end | |||
| - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex | |||
| { | |||
| owner->buttonClicked ((int) buttonIndex); | |||
| alertView.hidden = true; | |||
| } | |||
| @end | |||
| namespace juce | |||
| { | |||
| #endif | |||
| namespace juce | |||
| { | |||
| //============================================================================== | |||
| #if JUCE_MODAL_LOOPS_PERMITTED | |||