UMSocialHandler.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. //
  2. // UMSShareDataTypeTableViewController.h
  3. // SocialSDK
  4. //
  5. // Created by umeng on 16/4/14.
  6. // Copyright © 2016年 dongjianxiong. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "UMSocialPlatformConfig.h"
  10. #import "UMSocialPlatformProvider.h"
  11. extern NSString *const UMSocialErrorDomain;
  12. extern NSString *const UMSocialShareDataTypeIllegalMessage;
  13. @class UMSocialHandlerConfig;
  14. /**
  15. * 实现所有平台的基类
  16. * @discuss
  17. * 前提条件:需要在主工程配置 other link flag -ObjC
  18. * 所有实现UMSocialHandler对应平台类型子类,需要重写如下方法:
  19. * 1.+(NSArray*) socialPlatformTypes; 返回对应平台的类型的数组,此处用数组是为了在微信和qq的平台是可以有不同的平台类型(微信,朋友圈等)与统一handler公用
  20. * 2.重写load函数:
  21. *
  22. * 代码示例:
  23. * +(void)load
  24. * {
  25. * [super load];//必须调用
  26. * }
  27. *
  28. * 重载后保证调用基类的[UMSocialHandler load]
  29. * 3.重写defaultManager单例类方法,保证运行时能找到defaultManager来获得当前的单例方法,保证其唯一性。
  30. */
  31. @interface UMSocialHandler : NSObject<UMSocialPlatformProvider>
  32. #pragma mark - 子类需要重载的类
  33. +(void)load;
  34. +(NSArray*) socialPlatformTypes;
  35. + (instancetype)defaultManager;
  36. #pragma mark -
  37. @property (nonatomic, copy) NSString *appID;
  38. @property (nonatomic, copy) NSString *appSecret;
  39. @property (nonatomic, copy) NSString *redirectURL;
  40. /**
  41. * 当前ViewController(用于一些特定平台弹出相应的页面,默认使用当前ViewController)
  42. * since 6.3把currentViewController修改为弱引用,防止用户传入后强引用用户传入的UIViewController,导致内存不释放,
  43. * 注意:如果传入currentViewController的时候,一定要保证在(执行对应的分享,授权,获得用户信息的接口需要传入此接口的时候)存在,否则导致弱引用为nil,没有弹出界面的效果。
  44. */
  45. @property (nonatomic, weak) UIViewController *currentViewController;
  46. @property (nonatomic, copy) UMSocialRequestCompletionHandler shareCompletionBlock;
  47. @property (nonatomic, copy) UMSocialRequestCompletionHandler authCompletionBlock;
  48. @property (nonatomic, copy) UMSocialRequestCompletionHandler userinfoCompletionBlock;
  49. @property (nonatomic, copy) UMSocialRequestCompletionHandler launchFromPlatformCompletionBlock;
  50. -(BOOL)searchForURLSchemeWithPrefix:(NSString *)prefix;
  51. -(void)setAppId:(NSString *)appID appSecret:(NSString *)secret url:(NSString *)url;
  52. -(void)saveuid:(NSString *)uid openid:(NSString *)openid accesstoken:(NSString *)token refreshtoken:(NSString *)retoken expiration:(id )expiration;
  53. #pragma mark - 6.0.3新加入的平台配置类
  54. @property(nonatomic,readonly,strong)UMSocialHandlerConfig* handlerConfig;
  55. @end
  56. /**
  57. * 针对平台限制的类别
  58. */
  59. @interface UMSocialHandler (UMSocialLimit)
  60. /**
  61. * 检查对应平台的数据数据是否超过限制
  62. *
  63. * @param text 源文本
  64. * @param textLimit 限制文本的大小
  65. *
  66. * @return YES 代表没有限制,NO 代表超过限制
  67. */
  68. -(BOOL) checkText:(NSString*)text withTextLimit:(NSUInteger)textLimit;
  69. /**
  70. * 检查对应平台的数据数据是否超过限制
  71. *
  72. * @param data 源文本
  73. * @param dataLimit 限制文本的大小
  74. *
  75. * @return YES 代表没有限制,NO 代表超过限制
  76. */
  77. -(BOOL) checkData:(NSData*)data withDataLimit:(NSUInteger)dataLimit;
  78. /**
  79. * 对应平台超过限制,就截断文本
  80. *
  81. * @param text 源文本
  82. * @param textLimit 限制文本的大小
  83. *
  84. * @return 返回的截断的文本
  85. */
  86. -(NSString*)truncationText:(NSString*)text withTextLimit:(NSUInteger)textLimit;
  87. /**
  88. * 压缩对应平台的图片数据到限制发送的大小
  89. *
  90. * @param imageData 对应的图片数据
  91. * @param imageLimit 限制图片的大小
  92. *
  93. * @return 新的压缩的数据
  94. * @dicuss 当前图片小于对应平台的限制大小就返回本身,反之就压缩到指定大小以下发送
  95. */
  96. -(NSData*)compressImageData:(NSData*)imageData withImageLimit:(NSUInteger)imageLimit;
  97. @end
  98. #pragma mark - 6.0.3新增的配置类,用于限制分享类型和分享的内容
  99. /**
  100. * UMeng 分享类型配置信息的基类
  101. */
  102. @interface UMSocialShareObjectConfig : NSObject
  103. /**
  104. * 标题
  105. * @note 标题的长度依各个平台的要求而定
  106. */
  107. @property (nonatomic, readwrite,assign) NSUInteger titleLimit;
  108. /**
  109. * 描述
  110. * @note 描述内容的长度依各个平台的要求而定
  111. */
  112. @property (nonatomic, readwrite,assign) NSUInteger descrLimit;
  113. /**
  114. * 缩略图数据的大小
  115. */
  116. @property (nonatomic, readwrite,assign) NSUInteger thumbImageDataLimit;
  117. /**
  118. * 缩略图URL的大小
  119. */
  120. @property (nonatomic, readwrite,assign) NSUInteger thumbImageUrlLimit;
  121. /**
  122. * 点击多媒体内容之后呼起第三方应用特定页面的scheme
  123. * @warning 长度小于255
  124. * //sina平台有此字段限制
  125. * @discuss 此字段目前不用
  126. */
  127. //@property (nonatomic, strong) NSString *schemeLimit;
  128. /**
  129. * @note 长度不能超过64字节
  130. * //微信平台有此字段
  131. * @discuss 此字段目前不用
  132. */
  133. //@property (nonatomic, retain) NSString *mediaTagName;
  134. @end
  135. /**
  136. * 分享文本类型的配置
  137. *
  138. */
  139. @interface UMSocialShareTextObjectConfig : UMSocialShareObjectConfig
  140. /**
  141. * 文本内容的限制
  142. */
  143. @property(nonatomic,readwrite,assign)NSUInteger textLimit;
  144. @end
  145. /**
  146. * 分享图片的类型配置
  147. */
  148. @interface UMSocialShareImageObjectConfig : UMSocialShareObjectConfig
  149. /**
  150. * 缩略图数据的大小
  151. */
  152. @property (nonatomic, readwrite,assign) NSUInteger shareImageDataLimit;
  153. /**
  154. * 缩略图数据的URL大小
  155. */
  156. @property (nonatomic, readwrite,assign) NSUInteger shareImageURLLimit;
  157. @end
  158. /**
  159. * 分享音乐的类型配置
  160. */
  161. @interface UMSocialShareMusicObjectConfig : UMSocialShareObjectConfig
  162. /**
  163. * 音乐网页的url地址
  164. */
  165. @property (nonatomic, readwrite,assign)NSUInteger musicUrlLimit;
  166. /**
  167. * 音乐lowband网页的url地址
  168. */
  169. @property (nonatomic, readwrite,assign)NSUInteger musicLowBandUrlLimit;
  170. /**
  171. * 音乐数据url地址
  172. */
  173. @property (nonatomic, readwrite,assign)NSUInteger musicDataUrlLimit;
  174. /**
  175. * 音乐lowband数据url地址
  176. */
  177. @property (nonatomic, readwrite,assign)NSUInteger musicLowBandDataUrlLimit;
  178. @end
  179. /**
  180. * 分享视频的类型配置
  181. */
  182. @interface UMSocialShareVideoObjectConfig : UMSocialShareObjectConfig
  183. /**
  184. * 视频网页的url
  185. */
  186. @property (nonatomic, readwrite,assign) NSUInteger videoUrlLimit;
  187. /**
  188. * 视频lowband网页的url
  189. */
  190. @property (nonatomic, readwrite,assign) NSUInteger videoLowBandUrlLimit;
  191. /**
  192. * 视频数据流url
  193. */
  194. @property (nonatomic, readwrite,assign) NSUInteger videoStreamUrlLimit;
  195. /**
  196. * 视频lowband数据流url
  197. */
  198. @property (nonatomic, readwrite,assign) NSUInteger videoLowBandStreamUrlLimit;
  199. @end
  200. /**
  201. * 分享webURL
  202. */
  203. @interface UMSocialShareWebpageObjectConfig : UMSocialShareObjectConfig
  204. /**
  205. * 网页的url地址
  206. */
  207. @property (nonatomic, readwrite,assign) NSUInteger webpageUrlLimit;
  208. @end
  209. /**
  210. * 分享Email的类型配置
  211. */
  212. @interface UMSocialShareEmailObjectConfig : UMSocialShareObjectConfig
  213. /**
  214. * 接收人
  215. */
  216. @property (nonatomic, readwrite,assign) NSUInteger toRecipientLimit;
  217. /**
  218. * 抄送人
  219. */
  220. @property (nonatomic, readwrite,assign) NSUInteger ccRecipientLimit;
  221. /**
  222. * 密送人
  223. */
  224. @property (nonatomic, readwrite,assign) NSUInteger bccRecipientLimit;
  225. /**
  226. * 文本内容
  227. */
  228. @property (nonatomic, readwrite,assign) NSUInteger emailContentLimit;
  229. /**
  230. * 图片大小
  231. */
  232. @property (nonatomic, readwrite,assign) NSUInteger emailImageDataLimit;
  233. /**
  234. * 图片URL大小
  235. */
  236. @property (nonatomic, readwrite,assign) NSUInteger emailImageUrlLimit;
  237. /**
  238. * 文件(NSData)
  239. */
  240. @property (nonatomic, readwrite,assign) NSUInteger emailSendDataLimit;
  241. /**
  242. * 允许的文件格式
  243. */
  244. @property (nonatomic, readwrite,strong) NSArray *fileType;
  245. /**
  246. * 文件名,(例如图片 imageName.png, 文件名后要跟文件后缀名,否则没法识别,导致类似图片不显示的问题)
  247. */
  248. @property (nonatomic, readwrite,assign) NSUInteger fileNameLimit;
  249. @end
  250. /**
  251. * 分享Email的类型配置
  252. */
  253. @interface UMSocialShareSmsObjectConfig : UMSocialShareObjectConfig
  254. /**
  255. * 接收人
  256. */
  257. @property (nonatomic, readwrite,assign) NSUInteger recipientLimit;
  258. /**
  259. * 文本内容
  260. */
  261. @property (nonatomic, readwrite,assign) NSUInteger smsContentLimit;
  262. /**
  263. * 图片
  264. */
  265. @property (nonatomic, readwrite,assign) NSUInteger smsImageDataLimit;
  266. @property (nonatomic, readwrite,assign) NSUInteger smsImageUrlLimit;
  267. /**
  268. * 文件数据(NSData)
  269. * 必填
  270. */
  271. @property (nonatomic, readwrite,assign) NSUInteger smsSendDataLimit;
  272. /**
  273. * 文件格式
  274. * 必填,必须指定数据格式,如png图片格式应传入@"png"
  275. */
  276. @property (nonatomic, readwrite,strong) NSArray *fileType;
  277. /**
  278. * 文件名,(例如图片 imageName.png, 文件名后要跟文件后缀名,否则没法识别,导致类似图片不显示的问题)
  279. */
  280. @property (nonatomic, readwrite,assign) NSUInteger fileNameLimit;
  281. /**
  282. * 文件地址url
  283. */
  284. @property (nonatomic, readwrite,assign) NSUInteger fileUrlLimit;
  285. @end
  286. /**
  287. * 此配置项是特定平台才有的,比如微信,
  288. */
  289. @interface UMSocialShareEmotionObjectConfig : UMSocialShareObjectConfig
  290. //表情的字节大小限制
  291. @property(nonatomic,readwrite,assign)NSUInteger emotionDataLimit;
  292. @end
  293. /**
  294. * 此配置项是特定平台才有的,比如微信,
  295. */
  296. @interface UMSocialShareFileObjectConfig : UMSocialShareObjectConfig
  297. @property (nonatomic, readwrite,assign) NSUInteger fileExtensionLimit;
  298. @property (nonatomic, readwrite,assign) NSUInteger fileDataLimit;
  299. @end
  300. /**
  301. * 此配置项是特定平台才有的,比如微信
  302. */
  303. @interface UMSocialShareExtendObjectConfig : UMSocialShareObjectConfig
  304. @property (nonatomic, readwrite,assign) NSUInteger urlLimit;
  305. @property (nonatomic, readwrite,assign) NSUInteger extInfoLimit;
  306. @property (nonatomic, readwrite,assign) NSUInteger fileDataLimit;
  307. @end
  308. /**
  309. * 每个平台的配置信息
  310. * 包括如下:
  311. * 1.对分享内容的限制。
  312. *
  313. */
  314. @interface UMSocialHandlerConfig : NSObject
  315. @property(nonatomic,readwrite,strong)UMSocialShareTextObjectConfig* shareTextObjectConfig;
  316. @property(nonatomic,readwrite,strong)UMSocialShareImageObjectConfig* shareImageObjectConfig;
  317. @property(nonatomic,readwrite,strong)UMSocialShareMusicObjectConfig* shareMusicObjectConfig;
  318. @property(nonatomic,readwrite,strong)UMSocialShareVideoObjectConfig* shareVideoObjectConfig;
  319. @property(nonatomic,readwrite,strong)UMSocialShareWebpageObjectConfig* shareWebpageObjectConfig;
  320. @property(nonatomic,readwrite,strong)UMSocialShareEmailObjectConfig* shareEmailObjectConfig;
  321. @property(nonatomic,readwrite,strong)UMSocialShareSmsObjectConfig* shareSmsObjectConfig;
  322. @property(nonatomic,readwrite,strong)UMSocialShareEmotionObjectConfig* shareEmotionObjectConfig;
  323. @property(nonatomic,readwrite,strong)UMSocialShareFileObjectConfig* shareFileObjectConfig;
  324. @property(nonatomic,readwrite,strong)UMSocialShareExtendObjectConfig* shareExtendObjectConfig;
  325. //检查输入的text是否符合对应平台的输入
  326. +(BOOL) checkText:(NSString*)text withTextLimit:(NSUInteger)textLimit;
  327. +(BOOL) checkData:(NSData*)data withDataLimit:(NSUInteger)dataLimit;
  328. +(NSString*) truncationText:(NSString*)text withTextLimit:(NSUInteger)textLimit;
  329. //压缩图片
  330. + (NSData *)compressImageData:(NSData*)imageData toLength:(CGFloat)imageLimit;
  331. + (NSData *)compressImage:(UIImage*)image toLength:(CGFloat)imageLimit;
  332. @end