SHARE
TWEET

How to load Twitter Timeline Widget in a UIWebView

priore Mar 31st, 2013 882 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 1. Before create a HTML file named mywidget.html and with content :
  2. // <html>
  3. //    <head>
  4. //        <title></title>
  5. //        <script src="http://platform.twitter.com/widgets.js"> </script>
  6. //    </head>
  7. //    <body>
  8. //        <a class="twitter-timeline" height="%i" href="https://mobile.twitter.com/DaniloPriore" data-widget id="318522515175645184" data-chrome="noheader nofooter transparent" data-border-color="#cc0000" style="display:none"> </a>
  9. //    </body>
  10. //</html>
  11. //
  12. // you can take the your id number after have create a your widget from https://twitter.com/settings/widgets
  13. //
  14.  
  15.     // webview useragent
  16.     NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil];
  17.     [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
  18.    
  19.     // load html file
  20.     NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"mywidget" ofType:@"html" inDirectory:nil];
  21.     NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
  22.    
  23.     // fit height
  24.     htmlString = [NSString stringWithFormat:htmlString, (int)self.view.bounds.size.height];
  25.    
  26.     // show in browser (IBOutlet UIWebView *webView)
  27.     [webView loadHTMLString:htmlString baseURL:nil];
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top