Skip to content

Commit

Permalink
为导入首页数据做准备
Browse files Browse the repository at this point in the history
  • Loading branch information
zpz1237 committed Oct 22, 2015
1 parent aecd061 commit bb73b0f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
34 changes: 33 additions & 1 deletion zhihuDaily 2.0/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import Alamofire
import SwiftyJSON

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -23,6 +24,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// Alamofire.request(.GET, "http://news-at.zhihu.com/api/4/news/latest").responseJSON { (_, _, resultData) -> Void in
// let data = JSON(resultData.value!)
// //取到本日文章列表数据
// let topStoryData = data["top_stories"]
// let contentStoryData = data["stories"]
//
// //注入topStory
// for i in 0 ..< topStoryData.count {
// self.topStory.append(TopStoryModel(image: topStoryData[i]["image"].string!, id: String(topStoryData[i]["id"]), title: topStoryData[i]["title"].string!))
// }
// //注入contentStoryData
// for i in 0 ..< contentStoryData.count {
// self.contentStory.append(ContentStoryModel(images: [contentStoryData[i]["images"][0].string!], id: String(contentStoryData[i]["id"]), title: contentStoryData[i]["title"].string!))
// }
// //设置offsetYValue
// self.offsetYValue.append((120 + CGFloat(contentStoryData.count) * 93, "今日热闻"))
// }

print(getCalenderString(NSDate().dateByAddingTimeInterval(28800 - 86400).description))

//配置测试数据
topStory.append(TopStoryModel(image: "TopImage1", id: "", title: "胳膊上中了一枪"))
topStory.append(TopStoryModel(image: "TopImage2", id: "", title: "看看哪些镜头是超考验技术含量的,以后也好给电影打个公平的分"))
Expand Down Expand Up @@ -70,9 +91,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let themeStory: [ContentStoryModel] = contentStory + contentStory

themeContent = ThemeContentModel(stories: themeStory, background: "", name: "", editorsAvatars: ["avatar"])

return true
}

func getCalenderString(dateString: String) -> String {
var calenderString = ""
for character in dateString.characters {
if character != " " && character != "-"{
calenderString += "\(character)"
} else if character == " " {
break
}
}
return calenderString
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"images" : [
{
"idiom" : "universal",
"filename" : "LaunchImage.jpg",
"filename" : "77fab92338869abdec50071982b75246.jpg",
"scale" : "1x"
},
{
Expand Down
Binary file not shown.
9 changes: 8 additions & 1 deletion zhihuDaily 2.0/LaunchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ class LaunchViewController: UIViewController, JSAnimatedImagesViewDataSource {
text.text = NSUserDefaults.standardUserDefaults().objectForKey(launchTextKey) as! String
}

//下载下次的启动图像及版权文字
//下载下一次所需的启动页数据
Alamofire.request(.GET, "http://news-at.zhihu.com/api/4/start-image/1080*1776").responseJSON { (_, _, dataResult) -> Void in
guard dataResult.error == nil else {
print("获取数据失败")
return
}

//拿到text并保存
let text = JSON(dataResult.value!)["text"].string!
self.text.text = text
NSUserDefaults.standardUserDefaults().setObject(text, forKey: self.launchTextKey)

//拿到图像URL后取出图像并保存
Expand Down Expand Up @@ -68,6 +74,7 @@ class LaunchViewController: UIViewController, JSAnimatedImagesViewDataSource {
if NSUserDefaults.standardUserDefaults().objectForKey(launchImgKey) != nil {
return UIImage(data: NSUserDefaults.standardUserDefaults().objectForKey(launchImgKey) as! NSData)
}

return UIImage(named: "DemoLaunchImage")
}

Expand Down
5 changes: 5 additions & 0 deletions zhihuDaily 2.0/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class WebViewController: UIViewController, UIScrollViewDelegate, ParallaxHeaderV
func loadWebView(newsId: String) {
//获取网络数据,包括body css image image_source title 并拼接body与css后加载
Alamofire.request(.GET, "http://news-at.zhihu.com/api/4/news/7235309").responseJSON { (_, _, dataResult) -> Void in
guard dataResult.error == nil else {
print("获取数据失败")
return
}

let body = JSON(dataResult.value!)["body"].string!
let css = JSON(dataResult.value!)["css"][0].string!

Expand Down

0 comments on commit bb73b0f

Please sign in to comment.