fix for sizeWithFont:constrainedToSize:lineBreakMode deprecated in ios 7.0 #114

Closed
ShaharHD opened this Issue Feb 22, 2014 · 5 comments

4 participants

@ShaharHD

Patch for the deprecated warning in the code in latest version:

diff --git a/Mixpanel/MPNotificationViewController.m b/Mixpanel/MPNotificationViewController.m
index 2742fcd..4e93897 100644
--- a/Mixpanel/MPNotificationViewController.m
+++ b/Mixpanel/MPNotificationViewController.m
@@ -327,10 +327,30 @@

     // Position body label
     CGSize constraintSize = CGSizeMake(self.view.frame.size.width - MPNotifHeight - 12.5f, CGFLOAT_MAX);
-    CGSize sizeToFit = [_bodyLabel.text sizeWithFont:_bodyLabel.font
-                                   constrainedToSize:constraintSize
-                                       lineBreakMode:_bodyLabel.lineBreakMode];
-
+    CGSize sizeToFit;
+    // Use boundingRectWithSize for iOS 7 and above, sizeWithFont otherwise.
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
+    if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
+        sizeToFit = [_bodyLabel.text boundingRectWithSize:constraintSize
+                                               options:NSStringDrawingUsesLineFragmentOrigin
+                                            attributes:@{NSFontAttributeName: _bodyLabel.font}
+                                               context:nil].size;
+    } else {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated"
+        
+        sizeToFit = [_bodyLabel.text sizeWithFont:_bodyLabel.font
+                             constrainedToSize:constraintSize
+                                 lineBreakMode:_bodyLabel.lineBreakMode];
+        
+#pragma clang diagnostic pop
+    }
+#else
+    sizeToFit = [_prompt.text sizeWithFont:font
+                         constrainedToSize:constraintSize
+                             lineBreakMode:_prompt.lineBreakMode];
+#endif
+    
     _bodyLabel.frame = CGRectMake(MPNotifHeight, ceilf((MPNotifHeight - sizeToFit.height) / 2.0f) - 2.0f, ceilf(sizeToFit.width), ceilf(sizeToFit.height));
 }
@ShaharHD ShaharHD closed this Feb 23, 2014
@ShaharHD ShaharHD reopened this Feb 23, 2014
@smileyborg

👍 , please fix this.

@alex-hofsteede

@ShaharHD Yep, I will fix this. We already do this for MPSurveyQuestionViewController, so not doing it for Notifications is an oversight on our part.

@alex-hofsteede

This will be merged soon. #115

@ShaharHD

thanks.

right now we'll point our git submodule to this branch, but is there a set date for v2.3.3 ?
I kept going over the code, and I noticed this commit:
1fcf927

The patch is being done a bit differently.

shouldn't there be maybe a MACRO or library function which will make all those checks and code streamlined across the project?

@ShaharHD

@alex-hofsteede is there a reason this fix is not being merged into the master branch?
didn't happen in 2.3.2 and not in 2.3.3.

@malectro malectro closed this Feb 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment