Skip to content

Commit

Permalink
带时间戳缓存失败
Browse files Browse the repository at this point in the history
  • Loading branch information
MQZHot committed Dec 27, 2017
1 parent 0eeefa2 commit d2d4739
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 7 deletions.
4 changes: 4 additions & 0 deletions DaisyNet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
D64291201F8CD40900B1CB61 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D642911F1F8CD40900B1CB61 /* Assets.xcassets */; };
D64291231F8CD40900B1CB61 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D64291211F8CD40900B1CB61 /* LaunchScreen.storyboard */; };
D66459BA1F8E0232005D20AE /* MainTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66459B91F8E0232005D20AE /* MainTableViewController.swift */; };
D6BF12FF1FE69C8C00067D39 /* UploadViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BF12FE1FE69C8C00067D39 /* UploadViewController.swift */; };
D6F1C4AA1F924D0200C0F079 /* DownloadCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F1C4A81F924D0200C0F079 /* DownloadCell.swift */; };
D6F1C4AB1F924D0200C0F079 /* DownloadCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6F1C4A91F924D0200C0F079 /* DownloadCell.xib */; };
D6F1C4AD1F9250C600C0F079 /* DownloadTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F1C4AC1F9250C600C0F079 /* DownloadTableViewController.swift */; };
Expand All @@ -45,6 +46,7 @@
D64291221F8CD40900B1CB61 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
D64291241F8CD40900B1CB61 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D66459B91F8E0232005D20AE /* MainTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewController.swift; sourceTree = "<group>"; };
D6BF12FE1FE69C8C00067D39 /* UploadViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadViewController.swift; sourceTree = "<group>"; };
D6F1C4A81F924D0200C0F079 /* DownloadCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadCell.swift; sourceTree = "<group>"; };
D6F1C4A91F924D0200C0F079 /* DownloadCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DownloadCell.xib; sourceTree = "<group>"; };
D6F1C4AC1F9250C600C0F079 /* DownloadTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadTableViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -98,6 +100,7 @@
D6F1C4AC1F9250C600C0F079 /* DownloadTableViewController.swift */,
D6F1C4A81F924D0200C0F079 /* DownloadCell.swift */,
D6F1C4A91F924D0200C0F079 /* DownloadCell.xib */,
D6BF12FE1FE69C8C00067D39 /* UploadViewController.swift */,
D642911C1F8CD40900B1CB61 /* Main.storyboard */,
D642911F1F8CD40900B1CB61 /* Assets.xcassets */,
D64291211F8CD40900B1CB61 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -262,6 +265,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D6BF12FF1FE69C8C00067D39 /* UploadViewController.swift in Sources */,
D63F099D1FA605FF00D15881 /* CacheManager.swift in Sources */,
D63F099E1FA605FF00D15881 /* DaisyLog.swift in Sources */,
D63F09AA1FA6131000D15881 /* CacheKey.swift in Sources */,
Expand Down
Binary file not shown.
53 changes: 49 additions & 4 deletions DaisyNet/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Ul4-Ue-Bb8">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Ul4-Ue-Bb8">
<device id="retina3_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -24,7 +24,7 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="47"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="lHp-sp-JtX" id="wJp-OK-q3c">
<rect key="frame" x="0.0" y="0.0" width="287" height="46.5"/>
<rect key="frame" x="0.0" y="0.0" width="286" height="46.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="网络请求" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="TA7-6W-idb">
Expand All @@ -44,7 +44,7 @@
<rect key="frame" x="0.0" y="47" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="2Ec-p3-x32" id="UGe-Sd-ODm">
<rect key="frame" x="0.0" y="0.0" width="287" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="286" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="下载" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="0Lf-Qs-5MQ">
Expand All @@ -60,6 +60,26 @@
<segue destination="dKp-jH-Om0" kind="show" id="Au7-Xg-TgU"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="SDj-ww-Htn" style="IBUITableViewCellStyleDefault" id="GSW-yL-rl8">
<rect key="frame" x="0.0" y="91" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="GSW-yL-rl8" id="ecA-EU-z0h">
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="上传" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="SDj-ww-Htn">
<rect key="frame" x="16" y="0.0" width="288" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="Lr6-pg-GTx" kind="show" id="Vxh-wR-GSe"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand All @@ -81,6 +101,31 @@
<point key="canvasLocation" x="-391.19999999999999" y="99.400299850074973"/>
</scene>
<!--Title-->
<scene sceneID="maf-Pg-WAh">
<objects>
<viewController id="Lr6-pg-GTx" customClass="UploadViewController" customModule="DaisyNet" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="58D-My-JtB"/>
<viewControllerLayoutGuide type="bottom" id="GQb-xO-7e7"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="oRG-mn-XbG">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<navigationItem key="navigationItem" title="Title" id="pwU-Hd-w7R">
<barButtonItem key="rightBarButtonItem" title="相册" id="iF3-KH-rCe">
<connections>
<action selector="photoBrowser:" destination="Lr6-pg-GTx" id="jfQ-aE-DL5"/>
</connections>
</barButtonItem>
</navigationItem>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4kN-W9-OV6" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-392" y="941"/>
</scene>
<!--Title-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="GetViewController" customModule="DaisyNet" customModuleProvider="target" sceneMemberID="viewController">
Expand Down
7 changes: 6 additions & 1 deletion DaisyNet/DaisyNet/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class DownloadManager {
{
let key = cacheKey(url, parameters, dynamicParams)
let taskManager = DownloadTaskManager(url, parameters: parameters, dynamicParams: dynamicParams)
taskManager.download(url, method: method, parameters: parameters, encoding: encoding, headers: headers)
var tempParam = parameters==nil ? [:] : parameters!
let dynamicTempParam = dynamicParams==nil ? [:] : dynamicParams!
dynamicTempParam.forEach { (arg) in
tempParam[arg.key] = arg.value
}
taskManager.download(url, method: method, parameters: tempParam, encoding: encoding, headers: headers)
self.downloadTasks[key] = taskManager
taskManager.cancelCompletion = {
self.downloadTasks.removeValue(forKey: key)
Expand Down
7 changes: 6 additions & 1 deletion DaisyNet/DaisyNet/RequestManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class RequestManager {
taskManager?.completionClosure = {
self.requestTasks.removeValue(forKey: key)
}
taskManager?.request(url, method: method, params: params, cacheKey: key, encoding: encoding, headers: headers)
var tempParam = params==nil ? [:] : params!
let dynamicTempParam = dynamicParams==nil ? [:] : dynamicParams!
dynamicTempParam.forEach { (arg) in
tempParam[arg.key] = arg.value
}
taskManager?.request(url, method: method, params: tempParam, cacheKey: key, encoding: encoding, headers: headers)
return taskManager!
}

Expand Down
1 change: 0 additions & 1 deletion DaisyNet/GetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class GetViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()


// DaisyNet.request(url, params: params).cache(true).cacheJson { json in
// /// 缓存数据
Expand Down
2 changes: 2 additions & 0 deletions DaisyNet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>是否允许打开相册</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
Expand Down
34 changes: 34 additions & 0 deletions DaisyNet/UploadViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// UploadViewController.swift
// DaisyNet
//
// Created by mengqingzheng on 2017/12/17.
// Copyright © 2017年 MQZHot. All rights reserved.
//

import UIKit



class UploadViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()


}

@IBAction func photoBrowser(_ sender: UIBarButtonItem) {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .photoLibrary
present(picker, animated: true, completion: nil)
}else{
print("读取相册错误")
}
}
}
extension UploadViewController: UIImagePickerControllerDelegate,UINavigationControllerDelegate {

}

0 comments on commit d2d4739

Please sign in to comment.