{"id":50,"date":"2008-04-18T03:20:19","date_gmt":"2008-04-18T11:20:19","guid":{"rendered":"http:\/\/blog.danielparnell.com\/?p=50"},"modified":"2008-04-18T03:20:19","modified_gmt":"2008-04-18T11:20:19","slug":"webview-woes","status":"publish","type":"post","link":"https:\/\/blog.danielparnell.com\/?p=50","title":{"rendered":"WebView woes"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; \">I have been working on a little blog posting app for my wife for some time called BlogThing. \u00a0The first version worked well enough that I released it for download from the Automagic Software site. \u00a0It used some pretty nasty stuff that iterated over the chunks in an NSAttributedString, and while it worked pretty well I decided I wanted something a little more future proof. \u00a0To that end I decided to look into using WebView in edit mode. \u00a0Under 10.4 this worked really nicely. \u00a0I could drag in imanges, set the fonts and do all sorts of really neat things. \u00a0Unfortunately under 10.5 dragging and pasting images into the blog posting just stopped working \ud83d\ude41 and I&#8217;ve not had a lot of time to look into it. \u00a0Tonight I&#8217;ve managed to get it working well enough that I think I can finally give it to my wife to play with.<\/p>\n<div><\/div>\n<div>The following is an example of what I&#8217;ve had to do to get dragging to work the way I want it do. \u00a0I really don&#8217;t like it though<\/p>\n<div>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\">&#8211; (<span style=\"color: #aa0d91\">unsigned<\/span>)webView:(<span style=\"color: #5c2699\">WebView<\/span> *)sender dragDestinationActionMaskForDraggingInfo:(<span style=\"color: #aa0d91\">id<\/span> &lt;<span style=\"color: #5c2699\">NSDraggingInfo<\/span>>)draggingInfo {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\"><span style=\"white-space:pre\">\t<\/span><span style=\"color: #5c2699\">NSPasteboard<\/span>* pb = [draggingInfo <span style=\"color: #2e0d6e\">draggingPasteboard<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t<\/span><\/span><span style=\"color: #aa0d91\">if<\/span><span style=\"color: #000000\">([pb <\/span>availableTypeFromArray<span style=\"color: #000000\">: [<\/span><span style=\"color: #5c2699\">NSArray<\/span><span style=\"color: #000000\"> <\/span>arrayWithObject<span style=\"color: #000000\">: <\/span><span style=\"color: #5c2699\">NSFilenamesPboardType<\/span><span style=\"color: #000000\">]]) {<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t\t<\/span><\/span>\/\/ @TODO: this code assumes that any file dragged in is an image!\u00a0 Bad things will probably happen if they aren&#8217;t<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #5c2699\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t\t<\/span><\/span>NSArray<span style=\"color: #000000\">* filenames = [pb <\/span><span style=\"color: #2e0d6e\">propertyListForType<\/span><span style=\"color: #000000\">: <\/span>NSFilenamesPboardType<span style=\"color: #000000\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #5c2699\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t\t<\/span><\/span>NSMutableString<span style=\"color: #000000\">* html = [<\/span>NSMutableString<span style=\"color: #000000\"> <\/span><span style=\"color: #2e0d6e\">string<\/span><span style=\"color: #000000\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><span style=\"white-space:pre\">\t\t<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\"><span style=\"white-space:pre\">\t\t<\/span><span style=\"color: #aa0d91\">for<\/span>(<span style=\"color: #5c2699\">NSString<\/span>* filename <span style=\"color: #aa0d91\">in<\/span> filenames) {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t\t\t<\/span>[html <\/span>appendFormat<span style=\"color: #000000\">: <\/span><span style=\"color: #c41a16\">@&#8221;&lt;img src=\\&#8221;%@\\&#8221;\/>&#8221;<\/span><span style=\"color: #000000\">, [[[<\/span><span style=\"color: #5c2699\">NSURL<\/span><span style=\"color: #000000\"> <\/span>alloc<span style=\"color: #000000\">] <\/span>initFileURLWithPath<span style=\"color: #000000\">: filename] <\/span>absoluteString<span style=\"color: #000000\">]];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\"><span style=\"white-space:pre\">\t\t<\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><span style=\"white-space:pre\">\t\t<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t\t<\/span>[pb <\/span>declareTypes<span style=\"color: #000000\">: [<\/span><span style=\"color: #5c2699\">NSArray<\/span><span style=\"color: #000000\"> <\/span>arrayWithObject<span style=\"color: #000000\">: <\/span><span style=\"color: #5c2699\">NSHTMLPboardType<\/span><span style=\"color: #000000\">] <\/span>owner<span style=\"color: #000000\">: <\/span><span style=\"color: #aa0d91\">self<\/span><span style=\"color: #000000\">];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\"><span style=\"white-space:pre\">\t\t<\/span>[pb <span style=\"color: #2e0d6e\">setString<\/span>: html <span style=\"color: #2e0d6e\">forType<\/span>: <span style=\"color: #5c2699\">NSHTMLPboardType<\/span>];<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\"><span style=\"white-space:pre\">\t<\/span>}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><span style=\"white-space:pre\">\t<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e\"><span style=\"color: #000000\"><span style=\"white-space:pre\">\t<\/span><\/span><span style=\"color: #aa0d91\">return<\/span><span style=\"color: #000000\"> <\/span>WebDragDestinationActionAny<span style=\"color: #000000\">;<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\">}<\/p>\n<div><\/div>\n<div><font face=\"Times\" size=\"4\"><span style=\"font-size: 16px;\">Incidentally I&#8217;m posting this with BlogThing 2.0<\/span><\/font><\/div>\n<div><font face=\"Times\" size=\"4\"><span style=\"font-size: 16px;\"><br \/><\/span><\/font><\/div>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have been working on a little blog posting app for my wife for some time called BlogThing. \u00a0The first version worked well enough that I released it for download from the Automagic Software site. \u00a0It used some pretty nasty stuff that iterated over the chunks in an NSAttributedString, and while it worked pretty well &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.danielparnell.com\/?p=50\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;WebView woes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,3,2,6],"tags":[],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-mac-os-x","category-programming","category-web","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p561S3-O","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":0,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.danielparnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}