Ios_cnblog project Development (based on Blog Park API Development)

Source: Internet
Author: User

In accordance with the Convention, first

Objective

Coincidentally, do this project is just in the blog park when you see an article Blog Park third-party client-I blog Park officially released the app Store, here to help paste the link, after all, I want to say this project.

However, even more coincidentally, and the author of the article, I was just graduating to find an internship (/(ㄒoㄒ)/~~), development easy to find work, hey, do a project practice practiced hand bar.

Then, the whole project has been done for about half a month, today is made 1.0 version, has been posted on GitHub (https://github.com/samAroundGitHub/CNBlog), welcome to the road to guide the exchange of people, point a? It's good to be encouraged (O (∩_∩) o).

Project Introduction

1. Tools and Materials

Blog Park official open Web API URL: (Thanks again mulberry, because I will not look for API ...) (╮(╯▽╰)╭))

    1. Http://wcf.open.cnblogs.com/news/help (News)
    2. Http://wcf.open.cnblogs.com/blog/help (blog)

  Third-party framework (this time to say not to use too many third-party, so for development efficiency only a few)

      1. Sdwebimage
      2. Mjrefresh
      3. Svprogresshud

2. UI Design

I'll put some of my UI masterpieces here. (^^)

The UI used in the project, like AppIcon, launchimage, and some placeholder icons I made myself (Sketch), and then part of Http://www.easyicon.net, and some of the previous project icons, I also have to download the app from Ituns, open its package want to take its picture, unexpectedly did not find that few, should be sent network request to get, do not know how to get the app picture resources, here is recommended a URL: IOS, how to imitate an app

Development difficulties

1. Blog Park API Data analysis

Blog Park The data returned is XML, so I chose to use the official Apple Nsxmlparser to parse, for this I have specifically written a tool class (Smxmlparsertool), here to introduce the usage, you need to drag to your project to use.

. h file

+ (Instancetype) sm_toolwithurlstring: (NSString *) urlstring nodeName: (NSString *) nodeName Completehandler: (void (^) ( Nsarray *contentarray, Nserror *error)) completerhandler;-(Instancetype) sm_initwithurlstring: (NSString *) urlString NodeName: (NSString *) nodeName Completehandler: (void (^) (Nsarray *contentarray, Nserror *error)) completerhandler;@ Property (Nonatomic, ReadOnly, strong) Nsarray *contentarray; @property (nonatomic, strong) NSString *nodename;

You only need to call the class method when you use it, [Smxmlparsertool sm_toolwithurlstring: ...], you need to pass in the name of an XML node, for example, the XML node structure of the blog park is as follows,

<doc><feed><title> Blog Park _48 hours reading </title><id>d2e2f719-12cd-414e-ac2c-9d376c950c8a; id=...</id>//Refresh Time <updated></updated><entry> </entry><entry> </entry> <entry> </entry></feed></doc>//Blog Information <entry>//Article id<id></id>//blog Title < title></title>//Article overview <summary></summary>//release time <published></published>//get time <updated></updated>//publisher Information <author>//name <name></name>//blog Home <uri></uri> <avatar>//Head 

You just pass in the @ "entry" and then you get the dictionary of the node entry with the key value for each child node and then deposit it to the Contentarray, The obtained data Contentarray can be used directly in the callback function Completehandler. Error messages are printed to the console if the parsing process occurs incorrectly.

2. The second difficulty is the data analysis of the blog Park API

Because blog Park returns the blog post format is in HTML format. So you need to parse the HTML statement. The method I use here is [UIWebView loadhtmlstring:.];

You will then find that the parsed page image will go beyond the display range, which is required to use [WebView stringbyevaluatingjavascriptfromstring:.] To change the image size with JavaScript

Set the width-height adaptation screen of the picture [WebView stringbyevaluatingjavascriptfromstring:[nsstring stringWithFormat:                                                     @ "var script = document.createelement (' script ');"                                                     "Script.type = ' text/javascript ';" "Script.text = \" Function resizeimages () {"" Var Myimg,oldwidth,oldhe ight; "" var maxwidth=%f; "                                                     Picture width "for (i=0;i <document.images.length;i++) {"                                                     "myimg = Document.images[i];"                                                     "OldWidth = Myimg.width;oldheight = Myimg.height;"                                                     "var scale = oldwidth/oldheight;"      "If (Myimg.width > MaxWidth) {"                                               "Myimg.width = Maxwidth;myimg.height = Maxwidth/scale;"                                                     "}"                                                     "}" "}\";"                                                     "    document.getElementsByTagName (' head ') [0].appendchild (script); ", kScreenW-20]];     [WebView stringbyevaluatingjavascriptfromstring:@ "resizeimages ();"];

This will allow you to display more than the picture in the range you want.

3. The third difficulty is also the blog Park API data analysis

Why did you say that this time? Because if you want to click on the image under the WebView to respond, you have to use the method just now [UIWebView loadhtmlstring: ...];

By default, clicking does not trigger the event, so use JavaScript to make the image have the onclick () method, then change the document.loaction value, implement the page jump, in the UIWebView proxy Method-(BOOL) WebView: ( UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: (Uiwebviewnavigationtype) Navigationtype; Capture event for processing

Add a picture to the OnClick method    nsstring *setimageonclickstring = [NSString stringWithFormat:                                       @ "function Setimageonclick () {                                       var IMGs = document.getelementsbytagname (' img ');                                       for (var i=0; i

My approach is to use the new Apple embedded Sfsafariviewcontroller to achieve the jump, the benefit is directly in the app to enjoy the features of safari, such as saving pictures, into the reading mode and so on, and still do not leave your app within the app. #import <SafariServices/SafariServices.h> required before using Sfsafariviewcontroller

4. The fourth difficulty is still the blog Park API data analysis

Drunk, isn't it. Ha ha. But the difficulty I'm talking about this time is logically not technically. Get the number of data up and down to get how much data, a total of how much data, not a one-time access to data in the case of how much data to avoid the flow of waste, anyway is a series of logic to solve the problem, due to a lot of situations, I do not post code, have encountered problems and exchange.

5. Tarbarhidewhenpush

Finally the fifth difficulty is not the API data parsing, but in fact Tarbarhidewhenpush is not difficult, but will often detours, When Uitabbarviewcontroller nested uinavgationcontroller attached uiviewcontroller, anyway, the relationship is complicated, you will find a lot of people ask hidesbottombarwhenpushed = Yes why does not work, I also Baidu has tried a lot of methods, such as

    self.hidesbottombarwhenpushed = YES;    [Self.navigationcontroller Pushviewcontroller: Animated:yes];    self.hidesbottombarwhenpushed = NO;

For example, add self.hidesbottombarwhenpushed = YES in Viewdidappear. It's a lot of arguments anyway, but it's not very effective.

My only solution is to call in the VC you want to hide TarBar

Push after hidden tabbar-(BOOL) hidesbottombarwhenpushed {    return YES;}

Write here first, already 3 points 25,, the project some features next time introduce it.

Ios_cnblog project Development (based on Blog Park API Development)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.