Skip to content

Instantly share code, notes, and snippets.

@priore
Created February 28, 2016 02:58
Show Gist options
  • Save priore/1652c14822bf742df107 to your computer and use it in GitHub Desktop.
Save priore/1652c14822bf742df107 to your computer and use it in GitHub Desktop.
How to load Twitter Timeline Widget in a UIWebView
// 1. Before create a HTML file named mywidget.html and with content :
// <html>
// <head>
// <title></title>
// <script src="http://platform.twitter.com/widgets.js"> </script>
// </head>
// <body>
// <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>
// </body>
//</html>
//
// you can take the your id number after have create a your widget from https://twitter.com/settings/widgets
//
// webview useragent
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];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
// load html file
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"mywidget" ofType:@"html" inDirectory:nil];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
// fit height
htmlString = [NSString stringWithFormat:htmlString, (int)self.view.bounds.size.height];
// show in browser (IBOutlet UIWebView *webView)
[webView loadHTMLString:htmlString baseURL:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment