天天省钱快报

ZmzAFNetworking.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // ZmzAFNetworking.h
  3. // afCach
  4. //
  5. // Created by CiHon-IOS2 on 16/9/29.
  6. // Copyright © 2016年 walkingzmz. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "AFNetworking.h"
  10. #import "YBCacheTool.h"
  11. typedef NS_ENUM(NSInteger,NetworkRequestType) {
  12. NetworkGetType,
  13. NetworkPostType
  14. };
  15. typedef void (^ZmzBlock)(id responseObject,NSError *error,BOOL isCache);
  16. typedef void (^ZmzDownBlock)(id responseo,id filepath,NSError *error);
  17. //用于上传回调
  18. /** 请求成功的Block */
  19. typedef void(^requestSuccessBlock)(id dic);
  20. /** 请求失败的Block */
  21. typedef void(^requestFailureBlock)(NSError *error);
  22. @interface YBCache : NSObject
  23. @property (nonatomic, copy) NSString *fileName;//缓存文件名
  24. @property (nonatomic, assign) BOOL result;//是否需要重新请求数据
  25. @end
  26. @interface ZmzAFNetworking : NSObject
  27. /**
  28. * 发送网络请求
  29. * @param params 参数
  30. * @param type 请求类型
  31. * @param resultBlock 返回结果:responseObject,error
  32. */
  33. -(void)requsetWithPath:(NSString *)path withParams:(NSDictionary *)params withCacheType:(YBCacheType)cacheType withRequestType:(NetworkRequestType)type withResult:(ZmzBlock)resultBlock;
  34. /**
  35. * 发送网络请求
  36. * @param downloadpath 下载路径
  37. * @param downloadblock 返回结果:responseObject,error
  38. */
  39. -(void)downloadWithrequest:(NSString *)urlString downloadpath:(NSString *)downloadpath downloadblock:(ZmzDownBlock)downloadblock;
  40. /**
  41. *
  42. * 取消所有请求
  43. */
  44. - (void)cancelAllRequest;
  45. /**
  46. *
  47. * 取消某个请求。如果是要取消某个请求,最好是引用接口所返回来的HYBURLSessionTask对象,
  48. * 然后调用对象的cancel方法。如果不想引用对象,这里额外提供了一种方法来实现取消某个请求
  49. *
  50. * @param url URL,可以是绝对URL,也可以是path(也就是不包括baseurl)
  51. */
  52. - (void)cancelRequestWithURL:(NSString *)url;
  53. /**
  54. * 上传图片
  55. *
  56. * @param url 请求url
  57. * @param imageData 要上传的文件流
  58. * @param completion 文件上传成功的回调
  59. *
  60. * @return 请求体
  61. */
  62. - (NSURLSessionTask *)uploadImageWithUrl:(NSString *)url
  63. WithParams:(NSDictionary*)params
  64. image:(NSData *)imageData
  65. filename:(NSString *)name
  66. mimeType:(NSString *)mimetype
  67. completion:(requestSuccessBlock)completion
  68. errorBlock:(requestFailureBlock)errorBlock;
  69. /**
  70. * 上传音视频文件
  71. *
  72. * @param url 请求url
  73. * @param vedioData 要上传的文件流
  74. * @param completion 文件上传成功的回调
  75. *
  76. * @return 请求体
  77. */
  78. - (NSURLSessionTask *)uploadVedioWithUrl:(NSString *)url
  79. WithParams:(NSDictionary*)params
  80. image:(NSData *)vedioData
  81. filename:(NSString *)name
  82. mimeType:(NSString *)mimetype
  83. completion:(requestSuccessBlock)completion
  84. errorBlock:(requestFailureBlock)errorBlock;
  85. @end