|
30 | 30 | #import <QuartzCore/QuartzCore.h> |
31 | 31 | #import <StoreKit/StoreKit.h> |
32 | 32 | #import "LPCountAggregator.h" |
| 33 | +#import "LPAlertMessageTemplate.h" |
| 34 | +#import "LPConfirmMessageTemplate.h" |
33 | 35 |
|
34 | 36 | #define APP_NAME (([[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]) ?: \ |
35 | 37 | ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"])) |
36 | 38 |
|
37 | | -#define LPMT_ALERT_NAME @"Alert" |
38 | | -#define LPMT_CONFIRM_NAME @"Confirm" |
39 | | -#define LPMT_PUSH_ASK_TO_ASK @"Push Ask to Ask" |
40 | | -#define LPMT_REGISTER_FOR_PUSH @"Register For Push" |
41 | | -#define LPMT_CENTER_POPUP_NAME @"Center Popup" |
42 | | -#define LPMT_INTERSTITIAL_NAME @"Interstitial" |
43 | | -#define LPMT_WEB_INTERSTITIAL_NAME @"Web Interstitial" |
44 | | -#define LPMT_OPEN_URL_NAME @"Open URL" |
45 | | -#define LPMT_HTML_NAME @"HTML" |
46 | | -#define LPMT_APP_RATING_NAME @"Request App Rating" |
47 | | -#define LPMT_ICON_CHANGE_NAME @"Change App Icon" |
48 | | - |
49 | | -#define LPMT_ARG_TITLE @"Title" |
50 | | -#define LPMT_ARG_MESSAGE @"Message" |
51 | | -#define LPMT_ARG_URL @"URL" |
52 | | -#define LPMT_ARG_URL_CLOSE @"Close URL" |
53 | | -#define LPMT_ARG_URL_OPEN @"Open URL" |
54 | | -#define LPMT_ARG_URL_TRACK @"Track URL" |
55 | | -#define LPMT_ARG_URL_ACTION @"Action URL" |
56 | | -#define LPMT_ARG_URL_TRACK_ACTION @"Track Action URL" |
57 | | -#define LPMT_ARG_DISMISS_ACTION @"Dismiss action" |
58 | | -#define LPMT_ARG_ACCEPT_ACTION @"Accept action" |
59 | | -#define LPMT_ARG_CANCEL_ACTION @"Cancel action" |
60 | | -#define LPMT_ARG_CANCEL_TEXT @"Cancel text" |
61 | | -#define LPMT_ARG_ACCEPT_TEXT @"Accept text" |
62 | | -#define LPMT_ARG_DISMISS_TEXT @"Dismiss text" |
63 | | -#define LPMT_HAS_DISMISS_BUTTON @"Has dismiss button" |
64 | | -#define LPMT_ARG_HTML_TEMPLATE @"__file__Template" |
65 | | - |
66 | | -#define LPMT_ARG_TITLE_TEXT @"Title.Text" |
67 | | -#define LPMT_ARG_TITLE_COLOR @"Title.Color" |
68 | | -#define LPMT_ARG_MESSAGE_TEXT @"Message.Text" |
69 | | -#define LPMT_ARG_MESSAGE_COLOR @"Message.Color" |
70 | | -#define LPMT_ARG_ACCEPT_BUTTON_TEXT @"Accept button.Text" |
71 | | -#define LPMT_ARG_ACCEPT_BUTTON_BACKGROUND_COLOR @"Accept button.Background color" |
72 | | -#define LPMT_ARG_ACCEPT_BUTTON_TEXT_COLOR @"Accept button.Text color" |
73 | | -#define LPMT_ARG_CANCEL_BUTTON_TEXT @"Cancel button.Text" |
74 | | -#define LPMT_ARG_CANCEL_BUTTON_BACKGROUND_COLOR @"Cancel button.Background color" |
75 | | -#define LPMT_ARG_CANCEL_BUTTON_TEXT_COLOR @"Cancel button.Text color" |
76 | | -#define LPMT_ARG_BACKGROUND_IMAGE @"Background image" |
77 | | -#define LPMT_ARG_BACKGROUND_COLOR @"Background color" |
78 | | -#define LPMT_ARG_LAYOUT_WIDTH @"Layout.Width" |
79 | | -#define LPMT_ARG_LAYOUT_HEIGHT @"Layout.Height" |
80 | | -#define LPMT_ARG_HTML_HEIGHT @"HTML Height" |
81 | | -#define LPMT_ARG_HTML_WIDTH @"HTML Width" |
82 | | -#define LPMT_ARG_HTML_ALIGN @"HTML Align" |
83 | | -#define LPMT_ARG_HTML_Y_OFFSET @"HTML Y Offset" |
84 | | -#define LPMT_ARG_HTML_TAP_OUTSIDE_TO_CLOSE @"Tap Outside to Close" |
85 | | -#define LPMT_ARG_HTML_ALIGN_TOP @"Top" |
86 | | -#define LPMT_ARG_HTML_ALIGN_BOTTOM @"Bottom" |
87 | | -#define LPMT_ARG_APP_ICON @"__iOSAppIcon" |
88 | | - |
89 | | -#define LPMT_DEFAULT_ALERT_MESSAGE @"Alert message goes here." |
90 | | -#define LPMT_DEFAULT_CONFIRM_MESSAGE @"Confirmation message goes here." |
91 | | -#define LPMT_DEFAULT_ASK_TO_ASK_MESSAGE @"Tap OK to receive important notifications from our app." |
92 | | -#define LPMT_DEFAULT_POPUP_MESSAGE @"Popup message goes here." |
93 | | -#define LPMT_DEFAULT_INTERSTITIAL_MESSAGE @"Interstitial message goes here." |
94 | | -#define LPMT_DEFAULT_OK_BUTTON_TEXT @"OK" |
95 | | -#define LPMT_DEFAULT_YES_BUTTON_TEXT @"Yes" |
96 | | -#define LPMT_DEFAULT_NO_BUTTON_TEXT @"No" |
97 | | -#define LPMT_DEFAULT_LATER_BUTTON_TEXT @"Maybe Later" |
98 | | -#define LPMT_DEFAULT_URL @"http://www.example.com" |
99 | | -#define LPMT_DEFAULT_CLOSE_URL @"http://leanplum/close" |
100 | | -#define LPMT_DEFAULT_OPEN_URL @"http://leanplum/loadFinished" |
101 | | -#define LPMT_DEFAULT_TRACK_URL @"http://leanplum/track" |
102 | | -#define LPMT_DEFAULT_ACTION_URL @"http://leanplum/runAction" |
103 | | -#define LPMT_DEFAULT_TRACK_ACTION_URL @"http://leanplum/runTrackedAction" |
104 | | -#define LPMT_DEFAULT_HAS_DISMISS_BUTTON YES |
105 | | -#define LPMT_DEFAULT_APP_ICON @"__iOSAppIcon-PrimaryIcon.png" |
106 | | - |
107 | | -#define LPMT_ICON_FILE_PREFIX @"__iOSAppIcon-" |
108 | | -#define LPMT_ICON_PRIMARY_NAME @"PrimaryIcon" |
109 | | - |
110 | | -#define LPMT_POPUP_ANIMATION_LENGTH 0.35 |
111 | | - |
112 | | -#define LPMT_ACCEPT_BUTTON_WIDTH 50 |
113 | | -#define LPMT_ACCEPT_BUTTON_HEIGHT 15 |
114 | | -#define LPMT_ACCEPT_BUTTON_MARGIN 10 |
115 | | -#define LPMT_TWO_BUTTON_PADDING 13 |
116 | | - |
117 | | -#define LPMT_DEFAULT_CENTER_POPUP_WIDTH 300 |
118 | | -#define LPMT_DEFAULT_CENTER_POPUP_HEIGHT 250 |
119 | | -#define LPMT_DEFAULT_HTML_HEIGHT 0 |
120 | | -#define LPMT_DEFAULT_HTML_ALIGN LPMT_ARG_LAYOUT_ALIGN_TOP |
121 | | - |
122 | | -#define LPMT_TITLE_LABEL_HEIGHT 30 |
123 | | - |
124 | | -#define LPMT_DISMISS_BUTTON_SIZE 32 |
125 | | - |
126 | | -#define LIGHT_GRAY (246.0/255.0) |
127 | | - |
128 | | -#ifdef __IPHONE_6_0 |
129 | | -# define ALIGN_CENTER NSTextAlignmentCenter |
130 | | -#else |
131 | | -# define ALIGN_CENTER UITextAlignmentCenter |
132 | | -#endif |
133 | | - |
134 | | -#define LP_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) |
135 | | - |
136 | | -#define LOG_LP_MESSAGE_EXCEPTION NSLog(@"Leanplum: Error in message template %@: %@\n%@", \ |
137 | | -context.actionName, exception, [exception callStackSymbols]) |
138 | 39 |
|
139 | 40 | static NSString *DEFAULTS_ASKED_TO_PUSH = @"__Leanplum_asked_to_push"; |
140 | 41 | static NSString *DEFAULTS_LEANPLUM_ENABLED_PUSH = @"__Leanplum_enabled_push"; |
@@ -230,89 +131,10 @@ + (UIViewController *)visibleViewController |
230 | 131 | // Please give us suggestions for other types of messages! |
231 | 132 | - (void)defineActions |
232 | 133 | { |
233 | | - [Leanplum defineAction:LPMT_ALERT_NAME |
234 | | - ofKind:kLeanplumActionKindMessage | kLeanplumActionKindAction |
235 | | - withArguments:@[ |
236 | | - [LPActionArg argNamed:LPMT_ARG_TITLE withString:APP_NAME], |
237 | | - [LPActionArg argNamed:LPMT_ARG_MESSAGE withString:LPMT_DEFAULT_ALERT_MESSAGE], |
238 | | - [LPActionArg argNamed:LPMT_ARG_DISMISS_TEXT withString:LPMT_DEFAULT_OK_BUTTON_TEXT], |
239 | | - [LPActionArg argNamed:LPMT_ARG_DISMISS_ACTION withAction:nil] |
240 | | - ] |
241 | | - withResponder:^BOOL(LPActionContext *context) { |
242 | | - @try { |
243 | | - if (NSClassFromString(@"UIAlertController")) { |
244 | | - UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) preferredStyle:UIAlertControllerStyleAlert]; |
245 | | - UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_DISMISS_TEXT], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { |
246 | | - [self alertDismissedWithButtonIndex:0]; |
247 | | - }]; |
248 | | - [alert addAction:action]; |
249 | | - |
250 | | - [[LPMessageTemplatesClass visibleViewController] |
251 | | - presentViewController:alert animated:YES completion:nil]; |
252 | | - } else |
253 | | - { |
254 | | - UIAlertView *alert = [[UIAlertView alloc] |
255 | | - initWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) |
256 | | - message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) |
257 | | - delegate:self |
258 | | - cancelButtonTitle:NSLocalizedString([context stringNamed:LPMT_ARG_DISMISS_TEXT], nil) |
259 | | - otherButtonTitles:nil]; |
260 | | - [alert show]; |
261 | | - } |
262 | 134 |
|
263 | | - [self->_contexts addObject:context]; |
264 | | - return YES; |
265 | | - } |
266 | | - @catch (NSException *exception) { |
267 | | - LOG_LP_MESSAGE_EXCEPTION; |
268 | | - return NO; |
269 | | - } |
270 | | - }]; |
271 | | - |
272 | | - [Leanplum defineAction:LPMT_CONFIRM_NAME |
273 | | - ofKind:kLeanplumActionKindMessage | kLeanplumActionKindAction |
274 | | - withArguments:@[ |
275 | | - [LPActionArg argNamed:LPMT_ARG_TITLE withString:APP_NAME], |
276 | | - [LPActionArg argNamed:LPMT_ARG_MESSAGE withString:LPMT_DEFAULT_CONFIRM_MESSAGE], |
277 | | - [LPActionArg argNamed:LPMT_ARG_ACCEPT_TEXT withString:LPMT_DEFAULT_YES_BUTTON_TEXT], |
278 | | - [LPActionArg argNamed:LPMT_ARG_CANCEL_TEXT withString:LPMT_DEFAULT_NO_BUTTON_TEXT], |
279 | | - [LPActionArg argNamed:LPMT_ARG_ACCEPT_ACTION withAction:nil], |
280 | | - [LPActionArg argNamed:LPMT_ARG_CANCEL_ACTION withAction:nil], |
281 | | - ] |
282 | | - withResponder:^BOOL(LPActionContext *context) { |
283 | | - @try { |
284 | | - if (NSClassFromString(@"UIAlertController")) { |
285 | | - UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) preferredStyle:UIAlertControllerStyleAlert]; |
286 | | - UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_CANCEL_TEXT], nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { |
287 | | - [self alertDismissedWithButtonIndex:0]; |
288 | | - }]; |
289 | | - [alert addAction:cancel]; |
290 | | - UIAlertAction *accept = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_ACCEPT_TEXT], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { |
291 | | - [self alertDismissedWithButtonIndex:1]; |
292 | | - }]; |
293 | | - [alert addAction:accept]; |
294 | | - |
295 | | - [[LPMessageTemplatesClass visibleViewController] |
296 | | - presentViewController:alert animated:YES completion:nil]; |
297 | | - } else |
298 | | - { |
299 | | - UIAlertView *alert = [[UIAlertView alloc] |
300 | | - initWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) |
301 | | - message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) |
302 | | - delegate:self |
303 | | - cancelButtonTitle:NSLocalizedString([context stringNamed:LPMT_ARG_CANCEL_TEXT], nil) |
304 | | - otherButtonTitles:NSLocalizedString([context stringNamed:LPMT_ARG_ACCEPT_TEXT], nil),nil]; |
305 | | - [alert show]; |
306 | | - } |
307 | | - [self->_contexts addObject:context]; |
308 | | - return YES; |
309 | | - } |
310 | | - @catch (NSException *exception) { |
311 | | - LOG_LP_MESSAGE_EXCEPTION; |
312 | | - return NO; |
313 | | - } |
314 | | - }]; |
315 | | - |
| 135 | + [[[LPAlertMessageTemplate alloc] init] defineActionWithContexts:_contexts]; |
| 136 | + [[[LPConfirmMessageTemplate alloc] init] defineActionWithContexts:_contexts]; |
| 137 | + |
316 | 138 | [Leanplum defineAction:LPMT_OPEN_URL_NAME |
317 | 139 | ofKind:kLeanplumActionKindAction |
318 | 140 | withArguments:@[[LPActionArg argNamed:LPMT_ARG_URL withString:LPMT_DEFAULT_URL]] |
@@ -533,34 +355,6 @@ - (void)defineActions |
533 | 355 | } |
534 | 356 | } |
535 | 357 |
|
536 | | -#pragma mark Alert and Confirm Logic |
537 | | - |
538 | | -- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex |
539 | | -{ |
540 | | - [self alertDismissedWithButtonIndex:buttonIndex]; |
541 | | -} |
542 | | - |
543 | | -- (void)alertDismissedWithButtonIndex:(NSInteger)buttonIndex |
544 | | -{ |
545 | | - LPActionContext *context = _contexts.lastObject; |
546 | | - @try { |
547 | | - [_contexts removeLastObject]; |
548 | | - |
549 | | - if ([context.actionName isEqualToString:LPMT_ALERT_NAME]) { |
550 | | - [context runActionNamed:LPMT_ARG_DISMISS_ACTION]; |
551 | | - } else { |
552 | | - if (buttonIndex == 1) { |
553 | | - [context runTrackedActionNamed:LPMT_ARG_ACCEPT_ACTION]; |
554 | | - } else { |
555 | | - [context runActionNamed:LPMT_ARG_CANCEL_ACTION]; |
556 | | - } |
557 | | - } |
558 | | - } |
559 | | - @catch (NSException *exception) { |
560 | | - LOG_LP_MESSAGE_EXCEPTION; |
561 | | - } |
562 | | -} |
563 | | - |
564 | 358 | #pragma mark Center Popup and Interstitial Logic |
565 | 359 |
|
566 | 360 | // Creates a 1x1 image with the specified color. |
|
0 commit comments