Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BetterContent

 BetterContent

iOS real time content modifications using websockets

Tweet

Other Decks in Programming

Transcript

  1. Content Fine Tuning Create Item Screen “Send your items to

    valets and they’ll sell it for you”
  2. Content Fine Tuning Create Item Screen “Send your items to

    valets and they’ll sell it for you. You get 70% of the proceedings.”
  3. Requirements • Fun to use • Easy installation • Zero

    configuration • Private access • Free • Open source
  4. Hook for app start + (void)load { [[NSNotificationCenter defaultCenter] addObserver:self

    selector:@selector(startEngine) name:UIApplicationDidFinishLaunchingNotification object:nil]; } Native Architecture Configuration
  5. @implementation UILabel (BTCLabel) - (BOOL)btcIsSerializable{ return YES; } - (NSString

    *)btcClass{ return @"label"; } Native Architecture Serializer
  6. Native Architecture Serializer @implementation UILabel (BTCLabel) - (NSDictionary *)btcAttributes{ return

    @{@"text": self.btcSafeText, @"font": @{ @"pointSize" : @(self.font.pointSize) @"color": [self btcHexColor]}}; } - (void)btcUpdateWithComponent:(NSDictionary *)newComponent{ self.text = [newComponent objectForKey:@"text"]; }
  7. Server Architecture var WebSocketServer = require('ws').Server; var wss = new

    WebSocketServer({server: server}); wss.on('connection', function (ws) { ws.on('message', function (data, flags) { var message = JSON.parse(data); if (message.type === 'register') { ... } if (message.type === 'ping') { ... } if (message.type === 'ui') { /* ALL THE MAGIC HAPPENS HERE */ } }); });
  8. Server Architecture function onUI(ws, message) { if (ws.appType == NATIVE_APP)

    { lastNativeMessages[ws.appName] = message; webClientSockets[ws.appName].send(JSON.stringify(message)); } if (ws.appType == WEB_CLIENT) { nativeSockets[ws.appName].send(JSON.stringify(message)); } }
  9. BetterContent.Components.label = { draw: function(component, element){ setAttributesOnElement(component.attributes, element); // text,

    font element.setAttribute('contenteditable', true); element.addEventListener("input", function(event) { var element = event.srcElement; var diffJSON = [{ 'key': element.getAttribute('key'), 'attributes': {'text': element.innerText}}]; BetterContent.ws.send(diffJSON); }, false); } } Web Client Architecture Parser
  10. What’s next? • Android support • Additional components • Additional

    attributes • App control • Heroku templates • Integrate into ponydebugger/FLEX • iOS Framework in addition to pod
  11. Hand free content management Screen 1 Screen 2 2. Use

    local content 1. First run No content
  12. Hand free content management Screen 1 Screen 2 .strings file

    on the server 3. Scrape content 4. Create Content Document