On my work, technology and related stuff....

Posts Tagged ‘Objective-C’

No comments

There are many instances where you would need to support multiple configurations within your iOS app beyond the standard debug and release project configuration. Let’s suppose you app needs to talk to different server deployments – Development, QA and Production. In this case , you would want your app targeted for a specific environment to be configured to talk to the appropriate  server deployment. This blog post describes how you can do that within your swift iOS app. Things are slightly different with Obj-C, where you could define preprocessor flags within your .xcconfig files created for each environment . But with limited support for macros in swift, we will follow a slightly different approach

Step 1: Create desired configurations for Dev, QA and Prod

  • Under Project-Demo ,  add new configurations based upon existing Debug and Release configurations.
  • Duplicate the Debug configuration as a “Dev” configuration and duplicate the Release configuration as “QA” and “Prod” configurations .
  • Delete the Debug and Release configuration

Step 2: Add new schemes for Dev, QA and Prod configurations

Step 3: Make sure that the schemes created in Step 2 are “visible”

Step 4: Edit schemes created in Step2 and associate it with the appropriate configuration

So associate the QA scheme with QA configuration , the Dev scheme with Dev configuration and the Prod scheme with Prod configuration.

Step 5: Add a new user-defined build setting under Build Settings under tab.

This setting has a different value for each of the configurations.

Step 6: Add a info.plist property corresponding to the user-defined setting

Step 7: In your app,  read the info.plist property

That's it. Take appropriate actions depending on the configuration setting.

A demo project can be downloaded from here.

1 comment

This post describes a way to scale the text content that is presented within a UIWebview of your iOS app. Often times, there is a need to zoom in or zoom out the text content presented within UIWebview container in response to user actions. •   Run a simple Javascript on the contents of the webview using the stringByEvaluatingJavaScriptFromString method in order to adjust the size of the text.
 

In the JS above, DEFAULTWEBVIEWFONTSIZE refers to the default font size of the text content presented within the web view and updatedFontSize refers to the desired font size. So for example, if DEFAULTWEBVIEWFONTSIZE is 18 and updatedFontSize is 9, then updatedFontSize*100/DEFAULTWEBVIEWFONTSIZE evaluates to 50.

 

•   Next step is to adjust the frame height of the web view so the scaled text content is visible. The simplest way to do this is to have the UIWebView as a subview of a scrollable view (UIScrollView or  its subclass ).  That way, you can adjust the web view frame height  and correspondingly, the content size of the scroll view that encompasses it. Adjusting the  web view height is a bit tricky as described below.

 

The sizeThatFits method on web view returns a size that best fits the content. The problem with this is that when you scale up, the method returns the updated size but if the web view is large enough to display the specified content, then scaling down will not update the frame size but instead, the current frame size is returned.

 

So first , reset the current frame height  of the web view to a small value like 1.

 

Now, obtain the frame size that would best fit the content. Since the current frame size is 1, we are scaling up. Update the frame size of the web view with the new frame size.

 

Finally, update the content size of the UIScrollView containing the web view to accommodate the scaled content.

 

You can download a sample project that scales the text content of web view from  here. Shown below are some screenshots of the app.