55// Please visit www.count.ly for more information.
66
77#import " CountlyCommon.h"
8+ #import " CountlyWebViewManager.h"
89#if (TARGET_OS_IOS)
910#import < WebKit/WebKit.h>
1011#endif
@@ -24,8 +25,13 @@ @interface CountlyFeedbackWidget ()
2425@property (nonatomic ) CLYFeedbackWidgetType type;
2526@property (nonatomic ) NSString * ID;
2627@property (nonatomic ) NSString * name;
28+ @property (nonatomic ) NSString * widgetVersion;
2729@property (nonatomic ) NSArray <NSString*>* tags;
2830@property (nonatomic ) NSDictionary * data;
31+ @property (nonatomic ) WidgetCallback widgetCallback;
32+ #if (TARGET_OS_IOS)
33+ @property (nonatomic ) CLYInternalViewController* webVC;
34+ #endif
2935@end
3036
3137
@@ -39,6 +45,7 @@ + (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary
3945 feedback.type = dictionary[@" type" ];
4046 feedback.name = dictionary[@" name" ];
4147 feedback.tags = dictionary[@" tg" ];
48+ feedback.widgetVersion = dictionary[@" wv" ];
4249 return feedback;
4350}
4451
@@ -52,25 +59,64 @@ - (void)present
5259- (void )presentWithAppearBlock : (void (^ __nullable)(void ))appearBlock andDismissBlock : (void (^ __nullable)(void ))dismissBlock
5360{
5461 CLY_LOG_I (@" %s %@ %@ " , __FUNCTION__, appearBlock, dismissBlock);
55- [ self presentWithCallback: ^(WidgetState widgetState) {
62+ id widgetCallback = ^(WidgetState widgetState) {
5663 if (appearBlock && widgetState == WIDGET_APPEARED) {
5764 appearBlock ();
5865 }
5966
6067 if (dismissBlock && widgetState == WIDGET_CLOSED) {
6168 dismissBlock ();
6269 }
63- }];
70+ };
71+
72+ [self presentWithCallback: widgetCallback];
73+ }
74+
75+ - (void )presentWidget_new : (WidgetCallback) widgetCallback ;
76+ {
77+ CLY_LOG_I (@" %s %@ " , __FUNCTION__, widgetCallback);
78+ if (!CountlyConsentManager.sharedInstance .consentForFeedback )
79+ return ;
80+
81+ CGSize size = [CountlyCommon.sharedInstance getWindowSize ];
82+
83+ dispatch_async (dispatch_get_main_queue (), ^ {
84+ CGRect frame = CGRectMake (0.0 , 0.0 , size.width , size.height );
85+
86+ // Log the URL and the frame
87+ CLY_LOG_I (@" %s , Placement frame: %@ " , __FUNCTION__, NSStringFromCGRect(frame));
88+
89+ CountlyWebViewManager* webViewManager = CountlyWebViewManager.new ;
90+ [webViewManager createWebViewWithURL: [self generateWidgetURL ] frame: frame appearBlock: ^
91+ {
92+ CLY_LOG_I (@" %s , Webview appeared" , __FUNCTION__);
93+ if (widgetCallback)
94+ widgetCallback (WIDGET_APPEARED);
95+ } dismissBlock: ^
96+ {
97+ CLY_LOG_I (@" %s , Webview dismissed" , __FUNCTION__);
98+ if (widgetCallback)
99+ widgetCallback (WIDGET_CLOSED);
100+ [self recordReservedEventForDismissing ];
101+ }];
102+ });
64103}
65104
66105- (void )presentWithCallback : (WidgetCallback) widgetCallback ;
67106{
68107 CLY_LOG_I (@" %s %@ " , __FUNCTION__, widgetCallback);
69108 if (!CountlyConsentManager.sharedInstance .consentForFeedback )
70109 return ;
110+
111+ if (self.widgetVersion && ![self .widgetVersion isKindOfClass: [NSNull class ]]) {
112+ [self presentWidget_new: widgetCallback];
113+ return ;
114+ }
115+
71116 __block CLYInternalViewController* webVC = CLYInternalViewController.new ;
72117 webVC.view .backgroundColor = [UIColor.blackColor colorWithAlphaComponent: 0.4 ];
73118 webVC.modalPresentationStyle = UIModalPresentationCustom;
119+
74120 // Configure WKWebView with non-persistent data store
75121 WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc ] init ];
76122 configuration.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore ];
@@ -79,11 +125,13 @@ - (void)presentWithCallback:(WidgetCallback) widgetCallback;
79125 webView.layer .shadowOpacity = 0.5 ;
80126 webView.layer .shadowOffset = CGSizeMake (0 .0f , 5 .0f );
81127 webView.layer .masksToBounds = NO ;
128+
82129 webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
83130 [webVC.view addSubview: webView];
84131 webVC.webView = webView;
85- NSURLRequest * request = [self displayRequest ];
132+ NSURLRequest * request = [NSURLRequest requestWithURL: [ self generateWidgetURL ] ];
86133 [webView loadRequest: request];
134+
87135 CLYButton* dismissButton = [CLYButton dismissAlertButton ];
88136 dismissButton.onClick = ^(id sender)
89137 {
@@ -193,7 +241,7 @@ - (NSURLRequest *)dataRequest
193241 }
194242}
195243
196- - (NSURLRequest *)displayRequest {
244+ - (NSURL *)generateWidgetURL {
197245 // Create the base URL with endpoint and feedback type
198246 NSMutableString *URL = [NSMutableString stringWithFormat: @" %@%@ /%@ " ,
199247 CountlyConnectionManager.sharedInstance.host,
@@ -227,7 +275,12 @@ - (NSURLRequest *)displayRequest {
227275 [URL appendFormat: @" ?%@ " , queryString];
228276
229277 // Create custom parameters
230- NSDictionary *customParams = @{@" tc" : @" 1" };
278+ NSMutableDictionary *customParams = [@{@" tc" : @" 1" } mutableCopy];
279+
280+ if (self.widgetVersion && ![self .widgetVersion isKindOfClass: [NSNull class ]]) {
281+ customParams[@" rw" ] = @" 1" ;
282+ customParams[@" xb" ] = @" 1" ;
283+ }
231284
232285 // Create JSON data from custom parameters
233286 NSError *error;
@@ -241,8 +294,7 @@ - (NSURLRequest *)displayRequest {
241294 [URL appendFormat: @" &custom=%@ " , customString.cly_URLEscaped];
242295 }
243296
244- // Create and return the NSURLRequest
245- return [NSURLRequest requestWithURL: [NSURL URLWithString: URL]];
297+ return [NSURL URLWithString: URL];
246298}
247299
248300
0 commit comments