SlideShare a Scribd company logo
Hotfixing iOS apps
with Javascript
Sergio Padrino Recio
About me…
• Sergio Padrino (@sergiou87)
• Started working on iOS on 2010
• Worked atTuenti as iOS engineer (2012-2013)
• Worked at Fever as iOS Lead engineer (2014)
• Working at Plex since July 2014 – Current iOSTeam Lead
About Plex
About Plex
Example case
Example case
• Submit to Apple.
• Wait for review: 7 days.
• In review: 3 hours.
• Release!
Example case
WTF??
Hotfixing iOS apps with Javascript
8 days later…
Hotfixing iOS apps with Javascript
Hotfixing iOS apps with Javascript
We are all Peter
Example case
• Extreme case, workflow full of flaws:
• Coder failed.
• Code reviewer failed.
• Testers failed.
• Apple… didn’t say anything.
Plex:The Monster
• Too many moving parts:
• Plex Media Server version
• User network setup
• Interoperability with other Plex players
• Audio/Video/Subtitle format
Hotfixing iOS apps with Javascript
Fixes are usually quick, but…
Apple App Review process
• Used to be 1 week.
• Now reduced to 1-3 days.
• Still not reliable…
• Reviewer testing the wrong binary.
• App rejected because… Apple 😒
• Christmas holidays.
• Sometimes just gets longer.
appreviewtimes.com
Can we improve this?
Can we improve this?
• Android and Web apps can be updated at any time.
• Native iOS apps need to bypass Apple review:
• Use a remote configuration (GroundControl).
• Embedded web pages can be updated.
• Or…
rollout.io
• Service to hotfix apps without Apple review:
• Surround method with try…catch
• Replace method argument or return value
• No-op a method
• Basic scripting
Hotfixing iOS apps with Javascript
rollout.io
• Main problems (for us):
• Their platform has the ability to change our app
remotely. If they’re compromised… 😱
• “Expensive” post-build script to upload dSym.
• Our dSym is massive and they had trouble
processing it 😆
DIY
• Can we do it ourselves… better?
• Recent pain working on AppleTV app:
• Too much Javascript 😖
• Objective-C magic
• My own solution… SPHotPatch
plex.tv
DIY
Configuration
file
(hotfixes)
Plex for iOS
MAGIC
✨
But… how??
But… how??
Method Swizzling!
Method Swizzling
An Example
- (void)doSomethingWrong {

self.array[self.array.count];

}











Method Swizzling
An Example
- (void)doSomethingWrong {

self.array[self.array.count];

}



- (void)safe_doSomethingWrong {

@try { 

[self safe_doSomethingWrong];

} @catch(…) { }

}
Method Swizzling
An Example
- (void)doSomethingWrong {

self.array[self.array.count];

}



- (void)safe_doSomethingWrong {

@try { 

[self safe_doSomethingWrong];

} @catch(…) { }

}
INFINITE
RECURSION?!
Method Swizzling
An Example
- (void)doSomethingWrong {

self.array[self.array.count];

}



- (void)safe_doSomethingWrong {

@try { 

[self safe_doSomethingWrong];

} @catch(…) { }

}
INFINITE
RECURSION?!
doSomethingWrong
Method Swizzling
An Example
array[array.count]
safe_doSomethingWrong
@try {



[self 

safe_doSomethingWrong];



} @catch(…) {}
doSomethingWrong
Method Swizzling
An Example
array[array.count]
safe_doSomethingWrong
@try {



[self 

safe_doSomethingWrong];



} @catch(…) {}
safe_doSomethingWrongdoSomethingWrong
@try {



[self 

safe_doSomethingWrong];



} @catch(…) {}
Method Swizzling
An Example
array[array.count]
doSomethingWrong
@try {



[self 

safe_doSomethingWrong];



} @catch(…) {}
Method Swizzling
An Example
array[array.count]
safe_doSomethingWrong
Hotfixing iOS apps with Javascript
Where is my Javascript??
• JavascriptCore since iOS 7.
• Run JS scripts from Objective-C.
• Bridging: call Objective-C code from JS.
• More Objective-C runtime magic.
Javascript Core
• Run Javascript scripts from Objective-C:
Bridging
• Invoke Objective-C code from Javascript:
MyCrashyClass
doSomethingWrong
Combine all that…
array[array.count]
MyCrashyClass
safe_doSomethingWrongdoSomethingWrong
JSContext *context = …

[context evaluate:hotfixString]
Combine all that…
array[array.count]
doSomethingWrong
MyCrashyClass
JSContext *context = …

[context evaluate:hotfixString]
…fixed!
array[array.count]
safe_doSomethingWrong
More Objective-C runtime?
• “Proxy” object that gives access to Obj-C stuff
from JS.
More Objective-C runtime?
• Box method parameters to JSValue.
• Unbox return value from JSValue ⚠
• A lot of boilerplate to support as many types as
possible.
• Took some “inspiration” from OCMockito.
Unboxing return value…
IMP newImp = imp_implementationWithBlock(^(id self, ...) 

{

va_list args;



// Box parameters from args and prepare script

NSString *script = ...;

JSValue *result = [context evaluateScript:script];



if ([result isString])

return [result toString];

else if ([result isNumber])

return [result toInt32];

}
Unboxing return value…
• Method parameters are easy: variadic arguments.
• There is no “wild card” for return types.
• The only option… override forwardInvocation:
• NSInvocation is the key!
Unboxing return value…
IMP newImp = imp_implementationWithBlock(^(id self,

NSInvocation *inv) 

{

// Box parameters from invocation and prepare script

NSString *script = ...;

JSValue *result = [context evaluateScript:script];



if (inv.methodSignature.methodReturnType == ‘@’)

[inv setReturnValue:[result toObject]];

else if (inv.methodSignature.methodReturnType == ‘i’)

[inv setReturnValue:[result toInt32]];

}
MyCrashyClass
doSomethingWrong
Real Life™
array[array.count]
forwardInvocation:
original implementation
MyCrashyClass
ORIGdoSomethingWrongdoSomethingWrong
_objc_msgForward
Real Life™
forwardInvocation:
original implementation
array[array.count]
MyCrashyClass
ORIGdoSomethingWrongdoSomethingWrong
_objc_msgForward
Real Life™
forwardInvocation:
original implementation
array[array.count]
MyCrashyClass
ORIGdoSomethingWrongdoSomethingWrong
_objc_msgForward
Real Life™
forwardInvocation:
original implementation
array[array.count]
ORIGforwardInvocation:
JSContext *context = …

[context evaluate:hotfixString]
MyCrashyClass
ORIGdoSomethingWrongdoSomethingWrong
_objc_msgForward
Real Life™
array[array.count]
ORIGforwardInvocation:forwardInvocation:
JSContext *context = …

[context evaluate:hotfixString]
original implementation
Hotfixing iOS apps with Javascript
Hotfixing iOS apps with Javascript
DEMO
SPHotPatch
• Share it with friends to show off…
• …until someone tells me about JSPatch
• Open Source
• Better JS syntax (pre-processing)
• Extensions to use C stuff (CoreGraphics…)
JSPatch
JSPatch in Plex
• Remote configuration file declares available patches.
• Patches belong to a:
• App version.
• App build.
• Patch channel (default: production).
JSPatch in Plex
• Multiple “channels” allow:
• Testing hotfixes before “releasing” them.
• Create custom patches for users if needed.
JSPatch in Plex
JSPatch in Plex
• More features:
• Safe patching: if the app crashes before the
patch can be downloaded and applied, next time
the whole patching process will be synchronous.
• Skip patching in the next run.
• Clear last patch.
Things you can do
Hotfixing
of course
Gather data
• For bugs hard/impossible to reproduce.
• Create specific patch channel for affected users.
• Deploy patches for those users.
• Ask them for feedback in the forums.
Gather data
• Example 1:
• Video stalls and stuttering.
• Patches to log more info.
• Patches to change different settings of the video
player.
Gather data
• Example 2:
• Weird AutoLayout crash on old devices.
• Crash stacktrace impossible to read: all Apple
code.
• Patches to change different bits of broken layout.
Rewrite the whole app in JS
Rewrite the whole app in JS
Things you CAN’T fix
Things you CAN’T fix
seriously…
• Virtually nothing?
• You REALLY can write your whole app with JSPatch!
• Create extensions for C stuff you need.
• Apply patches as soon as you can.
• At Plex, we leave out +load methods.
What about Swift?
• Depends on Objective-C runtime so…
• Only works with NSObject.
• No structs or primitive types.
• No classes not inheriting from NSObject.
What about Apple?
3.3.2 Except as set forth in the next paragraph, an Application may not
download or install executable code. Interpreted code may only be
used in an Application if all scripts, code and interpreters are packaged
in the Application and not downloaded. The only exceptions to the
foregoing are scripts and code downloaded and run by Apple's
built-in WebKit framework or JavascriptCore, provided that
such scripts and code do not change the primary purpose of
the Application by providing features or functionality that are
inconsistent with the intended and advertised purpose of the
Application as submitted to the App Store
What about Apple?
• Just Javascript code that runs in JavascriptCore.
• Small fixes, not changing the whole app.
Security
• Avoid downloading patches from unknown
sources.
• Don’t run JS scripts without a valid signature.
• Only allow to sign patches to a handful of people.
Good practices
• Don’t abuse JS patching. It’s just your safe net.
• Establish a proper workflow to catch bugs before
the release.
• Test, test, test.Automate as much as you can.
Good practices
• QA should find nothing. If they do, it should be a big
thing.
• If all the above fails and the bug has a huge impact,
hotfix it.
• JS hotfixes should be reviewed and tested too.
• Immediately after, submit another build. Never rely on
those hotfixes.
Questions?
Thank you!

More Related Content

What's hot (18)

PPTX
JavaFX - Sketch Board to Production
Yoav Aharoni
 
PDF
Angular Unit Testing from the Trenches
Justin James
 
PPTX
Angular Unit Testing
Alessandro Giorgetti
 
PPT
Beyond Unit Testing
Steve Loughran
 
PDF
Angular Unit Testing NDC Minn 2018
Justin James
 
PPTX
QA Fest 2018. Adam Stasiak. React Native is Coming – the story of hybrid mobi...
QAFest
 
PPTX
Extending burp with python
Hoang Nguyen
 
PDF
Effective testing with pytest
Hector Canto
 
PPTX
Testing React Applications
stbaechler
 
PDF
Don't Be Mocked by your Mocks - Best Practices using Mocks
Victor Rentea
 
PDF
[Mac] automation testing technical sharing - 2013 dec
Chloe Chen
 
PDF
Client side unit tests - using jasmine & karma
Adam Klein
 
PPT
Google mock for dummies
Harry Potter
 
PDF
Polyglot automation - QA Fest - 2015
Iakiv Kramarenko
 
KEY
Unit Test Your Database
David Wheeler
 
PDF
Invoke dynamite in Java EE with invoke dynamic
Antoine Sabot-Durand
 
PDF
Writing usableap isinpractice
Giovanni Asproni
 
PDF
Anatomy of a Gem: Bane
Daniel Wellman
 
JavaFX - Sketch Board to Production
Yoav Aharoni
 
Angular Unit Testing from the Trenches
Justin James
 
Angular Unit Testing
Alessandro Giorgetti
 
Beyond Unit Testing
Steve Loughran
 
Angular Unit Testing NDC Minn 2018
Justin James
 
QA Fest 2018. Adam Stasiak. React Native is Coming – the story of hybrid mobi...
QAFest
 
Extending burp with python
Hoang Nguyen
 
Effective testing with pytest
Hector Canto
 
Testing React Applications
stbaechler
 
Don't Be Mocked by your Mocks - Best Practices using Mocks
Victor Rentea
 
[Mac] automation testing technical sharing - 2013 dec
Chloe Chen
 
Client side unit tests - using jasmine & karma
Adam Klein
 
Google mock for dummies
Harry Potter
 
Polyglot automation - QA Fest - 2015
Iakiv Kramarenko
 
Unit Test Your Database
David Wheeler
 
Invoke dynamite in Java EE with invoke dynamic
Antoine Sabot-Durand
 
Writing usableap isinpractice
Giovanni Asproni
 
Anatomy of a Gem: Bane
Daniel Wellman
 

Similar to Hotfixing iOS apps with Javascript (20)

PPTX
Swift meetup22june2015
Claire Townend Gee
 
PPTX
Basic iOS Training with SWIFT - Part 4
Manoj Ellappan
 
PPTX
Real world software launch
Kunal Johar
 
PDF
A guide to hiring a great developer to build your first app (redacted version)
Oursky
 
PDF
Progressive web and the problem of JavaScript
Christian Heilmann
 
KEY
TxJS 2011
Brian LeRoux
 
PDF
The iOS technical interview: get your dream job as an iOS developer
Juan C Catalan
 
PDF
Surviving javascript.pptx
Tamas Rev
 
PDF
Refactor Front-end APIs & Accounting for Tech Debt
C4Media
 
PDF
Resume - Alsey Coleman Miller - iOS Developer
Alsey Miller
 
PDF
Why You Should Be Doing Contract-First API Development
DevenPhillips
 
PDF
Swiftstart - Provisioning Basics
lacyrhoades
 
PDF
iOS development best practices
Michal Juhas
 
PDF
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
apidays
 
PDF
How to fix a bug in production - Rollout.io
Rollout.io
 
PDF
"I have a framework idea" - Repeat less, share more.
Fabio Milano
 
PDF
Move fast and consumer driven contract test things
Alon Pe'er
 
PDF
Parse cloud code
維佋 唐
 
PDF
JavaScript isn't evil.
Christian Heilmann
 
PDF
RubyMotion Inspect Conference - 2013. (With speaker notes.)
alloy020
 
Swift meetup22june2015
Claire Townend Gee
 
Basic iOS Training with SWIFT - Part 4
Manoj Ellappan
 
Real world software launch
Kunal Johar
 
A guide to hiring a great developer to build your first app (redacted version)
Oursky
 
Progressive web and the problem of JavaScript
Christian Heilmann
 
TxJS 2011
Brian LeRoux
 
The iOS technical interview: get your dream job as an iOS developer
Juan C Catalan
 
Surviving javascript.pptx
Tamas Rev
 
Refactor Front-end APIs & Accounting for Tech Debt
C4Media
 
Resume - Alsey Coleman Miller - iOS Developer
Alsey Miller
 
Why You Should Be Doing Contract-First API Development
DevenPhillips
 
Swiftstart - Provisioning Basics
lacyrhoades
 
iOS development best practices
Michal Juhas
 
APIdays Paris 2019 - API Descriptions as Product Code by Phil Sturgeon, Stopl...
apidays
 
How to fix a bug in production - Rollout.io
Rollout.io
 
"I have a framework idea" - Repeat less, share more.
Fabio Milano
 
Move fast and consumer driven contract test things
Alon Pe'er
 
Parse cloud code
維佋 唐
 
JavaScript isn't evil.
Christian Heilmann
 
RubyMotion Inspect Conference - 2013. (With speaker notes.)
alloy020
 
Ad

Recently uploaded (20)

PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Ad

Hotfixing iOS apps with Javascript