3434#import " OSInAppMessageAction.h"
3535#import " OSInAppMessageController.h"
3636#import " OSInAppMessagePrompt.h"
37+ #import " OneSignalCommonDefines.h"
3738
3839@interface OneSignal ()
3940
@@ -72,6 +73,10 @@ @interface OSMessagingController ()
7273
7374@property (nonatomic , nullable ) NSObject <OSInAppMessagePrompt>*currentPromptAction;
7475
76+ @property (nonatomic , nullable ) NSArray <NSObject <OSInAppMessagePrompt> *> *currentPromptActions;
77+
78+ @property (nonatomic , nullable ) OSInAppMessage *currentInAppMessage;
79+
7580@property (nonatomic ) BOOL isAppInactive;
7681
7782@end
@@ -509,7 +514,8 @@ - (void)persistInAppMessageForRedisplay:(OSInAppMessage *)message {
509514 [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" persistInAppMessageForRedisplay saved redisplayedInAppMessages: %@ " , [redisplayedInAppMessages description ]]];
510515}
511516
512- - (void )handlePromptActions : (NSArray <NSObject <OSInAppMessagePrompt> *> *)promptActions {
517+ - (void )handlePromptActions : (NSArray <NSObject <OSInAppMessagePrompt> *> *)promptActions withMessage : (OSInAppMessage *)inAppMessage {
518+ _currentPromptAction = nil ;
513519 for (NSObject <OSInAppMessagePrompt> *promptAction in promptActions) {
514520 // Don't show prompt twice
515521 if (!promptAction.hasPrompted ) {
@@ -521,17 +527,40 @@ - (void)handlePromptActions:(NSArray<NSObject<OSInAppMessagePrompt> *> *)promptA
521527 if (_currentPromptAction) {
522528 [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" IAM prompt to handle: %@ " , [_currentPromptAction description ]]];
523529 _currentPromptAction.hasPrompted = YES ;
524- [_currentPromptAction handlePrompt: ^(BOOL accepted) {
525- _currentPromptAction = nil ;
526- [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" IAM prompt to handle finished accepted: %@ " , accepted ? @" YES" : @" NO" ]];
527- [self handlePromptActions: promptActions];
530+ [_currentPromptAction handlePrompt: ^(PromptActionResult result) {
531+ [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: [NSString stringWithFormat: @" IAM prompt to handle finished accepted: %u " , result]];
532+ if (inAppMessage.isPreview && result == LOCATION_PERMISSIONS_MISSING_INFO_PLIST) {
533+ [self showAlertDialogMessage: inAppMessage promptActions: promptActions];
534+ } else {
535+ [self handlePromptActions: promptActions withMessage: inAppMessage];
536+ }
528537 }];
529538 } else if (!_viewController) { // IAM dismissed by action
530539 [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" IAM with prompt dismissed from actionTaken" ];
540+ _currentInAppMessage = nil ;
541+ _currentPromptActions = nil ;
531542 [self evaluateMessageDisplayQueue ];
532543 }
533544}
534545
546+ - (void )showAlertDialogMessage : (OSInAppMessage *)inAppMessage
547+ promptActions : (NSArray <NSObject <OSInAppMessagePrompt> *> *)promptActions {
548+ _currentInAppMessage = inAppMessage;
549+ _currentPromptActions = promptActions;
550+ let messageTitle = @" Location Not Available" ;
551+ let message = @" Looks like this app doesn't have location services configured. Please see OneSignal docs for more information." ;
552+ UIAlertView *alert = [[UIAlertView alloc ] initWithTitle: messageTitle
553+ message: message
554+ delegate: self
555+ cancelButtonTitle: nil
556+ otherButtonTitles: @" OK" , nil ];
557+ [alert show ];
558+ }
559+
560+ - (void )alertView : (UIAlertView *)alertView clickedButtonAtIndex : (NSInteger )buttonIndex {
561+ [self handlePromptActions: _currentPromptActions withMessage: _currentInAppMessage];
562+ }
563+
535564- (void )messageViewDidSelectAction : (OSInAppMessage *)message withAction : (OSInAppMessageAction *)action {
536565 // Assign firstClick BOOL based on message being clicked previously or not
537566 action.firstClick = [message takeActionAsUnique ];
@@ -540,7 +569,7 @@ - (void)messageViewDidSelectAction:(OSInAppMessage *)message withAction:(OSInApp
540569 [self handleMessageActionWithURL: action];
541570
542571 if (action.promptActions && action.promptActions .count > 0 )
543- [self handlePromptActions: action.promptActions];
572+ [self handlePromptActions: action.promptActions withMessage: message ];
544573
545574 if (self.actionClickBlock )
546575 self.actionClickBlock (action);
0 commit comments