/
PWInAppManager.h
142 lines (106 loc) · 3.59 KB
/
PWInAppManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// PWInAppManager.h
// Pushwoosh SDK
// (c) Pushwoosh 2017
//
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
/**
`PWJavaScriptInterface` protocol is a representation of Javascript object that can be added at runtime into In-App Message HTML page
to provide native calls and callbacks to Objective-C/Swift.
Example:
Objective-C:
@code
@implementation JavaScriptInterface
- (void)nativeCall:(NSString*)str :(PWJavaScriptCallback*)callback {
[callback executeWithParam:str];
}
@end
...
[[PWInAppManager sharedManager] addJavascriptInterface:[JavaScriptInterface new] withName:@"ObjC"];
@endcode
JavaScript:
@code
ObjC.nativeCall("exampleString", function(str) {
console.log(str);
});
@endcode
*/
@protocol PWJavaScriptInterface
@optional
/**
Tells the delegate that In-App Message load stated
*/
- (void)onWebViewStartLoad:(UIWebView*)webView;
/**
Tells the delegate that In-App Message load finished
*/
- (void)onWebViewFinishLoad:(UIWebView*)webView;
/**
Tells the delegate that In-App Message is closing
*/
- (void)onWebViewStartClose:(UIWebView*)webView;
@end
/**
`PWJavaScriptCallback` is a representation of Javascript function
*/
@interface PWJavaScriptCallback : NSObject
/**
Invokes callback with no arguments
*/
- (NSString*) execute;
/**
Invokes callback with one argument
*/
- (NSString*) executeWithParam: (NSString*) param;
/**
Invokes callback with multiple arguments
*/
- (NSString*) executeWithParams: (NSArray*) params;
@end
#endif
/*
`PWInAppManager` class offers access to the singleton-instance of the inapp messages manager responsible for sending events and managing inapp message notifications.
*/
@interface PWInAppManager : NSObject
+ (instancetype)sharedManager;
/**
Resets capping of the Pushwoosh out-of-the-box In-App solutions.
*/
- (void)resetBusinessCasesFrequencyCapping;
/**
Set User indentifier. This could be Facebook ID, username or email, or any other user ID.
This allows data and events to be matched across multiple user devices.
*/
- (void)setUserId:(NSString *)userId;
/**
Move all events from oldUserId to newUserId if doMerge is true. If doMerge is false all events for oldUserId are removed.
@param oldUserId source user
@param newUserId destination user
@param doMerge if false all events for oldUserId are removed, if true all events for oldUserId are moved to newUserId
@param completion callback
*/
- (void)mergeUserId:(NSString *)oldUserId to:(NSString *)newUserId doMerge:(BOOL)doMerge completion:(void (^)(NSError *error))completion;
/**
Post events for In-App Messages. This can trigger In-App message display as specified in Pushwoosh Control Panel.
Example:
@code
[[PWInAppManager sharedManager] setUserId:@"96da2f590cd7246bbde0051047b0d6f7"];
[[PWInAppManager sharedManager] postEvent:@"buttonPressed" withAttributes:@{ @"buttonNumber" : @"4", @"buttonLabel" : @"Banner" } completion:nil];
@endcode
@param event name of the event
@param attributes NSDictionary of event attributes
@param completion function to call after posting event
*/
- (void)postEvent:(NSString *)event withAttributes:(NSDictionary *)attributes completion:(void (^)(NSError *error))completion;
/**
See `postEvent:withAttributes:completion:`
*/
- (void)postEvent:(NSString *)event withAttributes:(NSDictionary *)attributes;
#if TARGET_OS_IPHONE
/**
Adds javascript interface for In-App Messages. Interface will be accessible from javascript as object with specified `name` and functions defined in `interface` class.
*/
- (void)addJavascriptInterface:(NSObject<PWJavaScriptInterface>*)interface withName:(NSString*)name;
#endif
@end