Evaluating Javascript using WKWebView in iOS

Sample of page loaded in web view: <html> <body> <script> function getWindowInfo() { return { width: window.innerWidth || document.body.clientWidth, height: window.innerHeight || document.body.clientHeight } }; </script> </body> </html> In a UIView or UIViewController: import WebKit // Enable Javascript in web view let config = WKWebViewConfiguration() let prefs = WKPreferences() prefs.javaScriptEnabled = true config.preferences = prefs …

Lessons from writing Swift framework that works in Objective-C app

As mentioned in my previous post on Fix for Google Analytics pod not working in Swift framework a few months ago, I was helping to refactor a client’s outsourced mobile SDKs. Last month, one of their clients had issues using the iOS SDK in their Objective-C app. Turns out that the Swift framework, i.e. the …

Resize view to fit aspect ratio of video in Android ExoPlayer

Been playing with ExoPlayer in Android and trying to resize a view to fit the aspect ratio of the video being played, i.e. fill the view with the video. References: Change resize mode for ExoPlayer Change aspect ratio of SurfaceView for ExoPlayer video 5-part series on building video player using ExoPlayer import android.view.ViewGroup.LayoutParams; import com.google.android.exoplayer2.Player.EventListener; …

Print properties of object in Swift

Reference: StackOverflow – Print Struct name in swift Here’s the code for printing the properties of an object func printProperties(_ object: Any) { var properties = [String: Any]() Mirror(reflecting: object).children.forEach { (child) in if let property = child.label { properties[property] = child.value } } print(object) print(type(of: object)) print(properties) } How the output would look like …