AppDelegate.m 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. #import "AppDelegate.h"
  2. /******shark sdk *********/
  3. #import <ShareSDK/ShareSDK.h>
  4. #import <ShareSDKConnector/ShareSDKConnector.h>
  5. //腾讯开放平台(对应QQ和QQ空间)SDK头文件
  6. #import <TencentOpenAPI/TencentOAuth.h>
  7. #import <TencentOpenAPI/QQApiInterface.h>
  8. //微信SDK头文件
  9. //极光推送
  10. #import "JPUSHService.h"
  11. #import <JMessage/JMessage.h>
  12. /******shark sdk end*********/
  13. //腾讯bug监控
  14. #import <Bugly/Bugly.h>
  15. #import <WXApi.h>
  16. #import "YBTabBarController.h"
  17. //#import <FBSDKMessengerShareKit/FBSDKMessengerSharer.h>
  18. #import <Twitter/Twitter.h>
  19. #import "SPUncaughtExceptionHandler.h"
  20. #import "EBBannerView.h"
  21. //支付宝
  22. #import <AlipaySDK/AlipaySDK.h>
  23. //#include "TiSDKInterface.h"
  24. //发送位置
  25. #import <QMapKit/QMapKit.h>
  26. #import <QMapSearchKit/QMapSearchKit.h>
  27. #import "TXUGCBase.h"
  28. //友盟
  29. #import <UMCommon/UMCommon.h>
  30. #import <UMAnalytics/MobClick.h>
  31. #import "GuideViewController.h"
  32. @import CoreLocation;
  33. #import "RKUUIDManager.h"
  34. #import <TXLiveBase.h>
  35. #import "YBGetVideoObj.h"
  36. #import <notify.h>
  37. #import "YBPrivateVC.h"
  38. #import "YBStorageObj.h"
  39. #import "YBShareView.h"
  40. #import "OpenInstallSDK.h"
  41. #import "BTAppSwitch.h"
  42. #import "TUIKit.h"
  43. #import <TPNS-iOS/XGPush.h>
  44. #import <TPNS-iOS/XGPushPrivate.h>
  45. #import <ZFPlayer/ZFLandscapeRotationManager.h>
  46. #import <TXLiteAVSDK_Professional/V2TXLivePremier.h>
  47. @interface AppDelegate ()<CLLocationManagerDelegate,WXApiDelegate,JMessageDelegate,OpenInstallDelegate,XGPushDelegate,V2TXLivePremierObserver>
  48. {
  49. CLLocationManager *_lbsManager;
  50. NSNotification * sendEmccBack;
  51. CGFloat _coverRatio;
  52. }
  53. @property(nonatomic,strong)NSArray *scrollarrays;//轮播
  54. @end
  55. @implementation AppDelegate
  56. /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式
  57. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  58. // //可以这么写
  59. // if (self.allowOrentitaionRotation) {
  60. // return UIInterfaceOrientationMaskAllButUpsideDown;
  61. // }
  62. // return UIInterfaceOrientationMaskPortrait;
  63. ZFInterfaceOrientationMask orientationMask = [ZFLandscapeRotationManager supportedInterfaceOrientationsForWindow:window];
  64. if (orientationMask != ZFInterfaceOrientationMaskUnknow) {
  65. return (UIInterfaceOrientationMask)orientationMask;
  66. }
  67. /// 这里是非播放器VC支持的方向
  68. return UIInterfaceOrientationMaskPortrait;
  69. }
  70. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  71. // InstallUncaughtExceptionHandler();
  72. if (@available(iOS 15.0,*)) {
  73. [UITableView appearance].sectionHeaderTopPadding = 0;
  74. }
  75. [self setLanguage];
  76. if (![Config getOwnID]) {
  77. [Config saveUnified:[PublicObj visitorDic]];
  78. }
  79. NSString *deviceUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
  80. [RKUUIDManager saveUUID:deviceUUID];
  81. [Config saveFirstBonus:@"1"];
  82. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  83. [[SDWebImageDownloader sharedDownloader] setValue:nil forHTTPHeaderField:@"Accept"];
  84. [[SDWebImageDownloader sharedDownloader] setValue:h5url forHTTPHeaderField:@"referer"];
  85. [OpenInstallSDK initWithDelegate:self];
  86. // [BTAppSwitch setReturnURLScheme:@"hailongFengbao.payments"];
  87. [BTAppSwitch setReturnURLScheme:@"com.yunbao.1v1.payments"];
  88. self.window = [[UIWindow alloc]initWithFrame:CGRectMake(0,0,_window_width, _window_height)];
  89. if (@available(iOS 13.0, *)) {
  90. self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
  91. }
  92. self.window.rootViewController = [[YBNavigationController alloc] initWithRootViewController:[[GuideViewController alloc] init]];
  93. [self.window makeKeyAndVisible];
  94. if (showCopyright) {
  95. //启动图版本号、版权信息
  96. [self setVersionInfo];
  97. //反复测试延迟1s对版权、版本号展示效果最优
  98. sleep(1);
  99. }
  100. //腾讯im
  101. [[TUIKit sharedInstance]initV2IMSDKWithConfig:[TUIKitConfig defaultConfig]];
  102. //腾讯tpns推送
  103. [[XGPush defaultManager] configureClusterDomainName:TXPushClusterDomain];
  104. [[XGPush defaultManager] startXGWithAccessID:TXPushAccessID accessKey:TXPushAccessKey delegate:self];
  105. [[XGPush defaultManager] setEnableDebug:YES];
  106. // [TXLiveBase setLicenceURL:LicenceLiveUrl key:LicenceLiveKey];
  107. [V2TXLivePremier setLicence:LicenceLiveUrl key:LicenceLiveKey];
  108. [V2TXLivePremier setObserver:self];
  109. [TXUGCBase setLicenceURL:LicenceDspURL key:LicenceDspKey];
  110. //友盟
  111. [UMConfigure initWithAppkey:UMAppKey channel:UMChannel];
  112. [MobClick setScenarioType:E_UM_NORMAL];
  113. [IQKeyboardManager sharedManager].enable = YES;
  114. [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
  115. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  116. [Bugly startWithAppId:BuglyId];
  117. [self sysLocation];
  118. [self sendLocation];
  119. [self thirdPlant];
  120. //推送-IM
  121. [self setJPush:launchOptions];
  122. //获取后台配置信息
  123. [BGSetting getBgSettingUpdate:NO maintain:NO eventBack:nil];
  124. [common saveIsStart:@"1"];
  125. //生命周期监听
  126. [[RKKeepAlive sharedKeepInstance] startAppLifeCycleMonitor];
  127. [self getNetJudge];
  128. return YES;
  129. }
  130. #pragma mark - V2TXLivePremierObserver
  131. - (void)onLicenceLoaded:(int)result Reason:(NSString *)reason {
  132. NSLog(@"onLicenceLoaded: result:%d reason:%@", result, reason);
  133. }
  134. -(void)getNetJudge {
  135. AFNetworkReachabilityManager *netManager = [AFNetworkReachabilityManager sharedManager];
  136. [netManager startMonitoring];
  137. [netManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
  138. if (status == AFNetworkReachabilityStatusReachableViaWiFi){
  139. [PublicObj saveNetReachability:@"wifi"];
  140. }else if (status == AFNetworkReachabilityStatusReachableViaWWAN){
  141. [PublicObj saveNetReachability:@"wwan"];
  142. }else{
  143. [PublicObj saveNetReachability:@"unknown"];
  144. }
  145. }];
  146. }
  147. #pragma mark - 设置语言
  148. -(void)setLanguage {
  149. //默认值【有语言开发删除此行】
  150. // [[NSUserDefaults standardUserDefaults] setObject:ZH_CN forKey:CurrentLanguage];
  151. // 获取历史
  152. if (lagType) {
  153. [[NSUserDefaults standardUserDefaults] setObject:lagType forKey:CurrentLanguage];
  154. }else{
  155. BOOL isCn = [[YBLanguageTools shareInstance] isChinese];
  156. if (isCn) {
  157. [[NSUserDefaults standardUserDefaults] setObject:ZH_CN forKey:CurrentLanguage];
  158. }else{
  159. [[NSUserDefaults standardUserDefaults] setObject:EN forKey:CurrentLanguage];
  160. }
  161. }
  162. [[YBLanguageTools shareInstance] resetLanguage:[[NSUserDefaults standardUserDefaults] objectForKey:CurrentLanguage] withFrom:@"appdelegate"];
  163. }
  164. #pragma mark - 杀进程
  165. - (void)applicationWillTerminate:(UIApplication *)application{
  166. [StorageConfig clearResTime];
  167. [[NSNotificationCenter defaultCenter] postNotificationName:@"shajincheng" object:nil];
  168. if (self.lifeCycleEvent) {
  169. self.lifeCycleEvent(APPLifeCycle_WillTerminate);
  170. }
  171. [[YBYoungManager shareInstance] appKilled];
  172. [[YBActiveManager shareManager] resetActive];
  173. }
  174. #pragma mark - App进入后台
  175. - (void)applicationDidEnterBackground:(UIApplication *)application {
  176. if (self.lifeCycleEvent) {
  177. self.lifeCycleEvent(APPLifeCycle_EnterBackground);
  178. }
  179. [[YBYoungManager shareInstance] appResignActive];
  180. }
  181. #pragma mark - App将要从后台返回
  182. - (void)applicationWillEnterForeground:(UIApplication *)application {
  183. [application setApplicationIconBadgeNumber:0];
  184. [JPUSHService setBadge:0];
  185. if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"rk_paying"]isEqual:@"1"]) {
  186. [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"rk_paying"];
  187. [MBProgressHUD hideHUD];
  188. }
  189. if (self.lifeCycleEvent) {
  190. self.lifeCycleEvent(APPLifeCycle_EnterForeground);
  191. }
  192. [[YBYoungManager shareInstance] appActive];
  193. }
  194. #pragma mark - 推送-IM
  195. -(void)setJPush:(NSDictionary *)launchOptions{
  196. UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];
  197. [[UIApplication sharedApplication] registerUserNotificationSettings:setting];
  198. [[UIApplication sharedApplication] registerForRemoteNotifications];
  199. if([[Config getOwnID] intValue]>0) {
  200. [[YBImManager shareInstance] imLogin];
  201. }
  202. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bannerDidClick:) name:EBBannerViewDidClickNotification object:nil];
  203. // if([Config getOwnID]!=nil && ![[Config getOwnID] isEqual:@"-9999"]) {
  204. // NSString *aliasStr = [NSString stringWithFormat:@"%@PUSH",[Config getOwnID]];
  205. // [JMSGUser loginWithUsername:[NSString stringWithFormat:@"%@%@",JmessageName,[Config getOwnID]] password:aliasStr completionHandler:^(id resultObject, NSError *error) {
  206. // if (!error) {
  207. // NSLog(@"appdelegate-极光IM登录成功");
  208. // } else {
  209. // NSLog(@"appdelegate-极光IM登录失败");
  210. // }
  211. // }];
  212. // }
  213. // //IM
  214. // [JMessage addDelegate:self withConversation:nil];
  215. // [JMessage setupJMessage:launchOptions appKey:JpushAppKey channel:Jchannel apsForProduction:isProduction category:nil messageRoaming:YES];
  216. //
  217. // //推送
  218. // if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  219. // //可以添加自定义categories
  220. // [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
  221. // UIUserNotificationTypeSound |
  222. // UIUserNotificationTypeAlert)
  223. // categories:nil];
  224. // }
  225. // [JPUSHService setupWithOption:launchOptions appKey:JpushAppKey
  226. // channel:Jchannel
  227. // apsForProduction:isProduction
  228. // advertisingIdentifier:nil];
  229. // [JPUSHService setBadge:0];
  230. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bannerDidClick:) name:EBBannerViewDidClickNotification object:nil];
  231. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jmNot:) name:kJPFNetworkDidSetupNotification object:nil];
  232. }
  233. //极光数据库升级通知
  234. - (void)onDBMigrateStart {
  235. NSLog(@"onDBmigrateStart in appdelegate");
  236. _isDBMigrating = YES;
  237. }
  238. //极光数据库升级完成通知
  239. - (void)onDBMigrateFinishedWithError:(NSError *)error {
  240. NSLog(@"onDBmigrateFinish in appdelegate");
  241. _isDBMigrating = NO;
  242. [[NSNotificationCenter defaultCenter] postNotificationName:kDBMigrateFinishNotification object:nil];
  243. }
  244. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{
  245. //处理通过openinstall一键唤起App时传递的数据
  246. [OpenInstallSDK continueUserActivity:userActivity];
  247. //其他第三方回调;
  248. return YES;
  249. }
  250. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  251. NSLog(@"==============%@", [NSString stringWithFormat:@"Device Token: %@", deviceToken]);
  252. [JPUSHService registerDeviceToken:deviceToken];
  253. [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
  254. //1.记录registrationID,登陆的时候上传一次
  255. _jgRegistrationID = registrationID;
  256. //2.保证打开app的时候再上传一次(上传接口会判断游客和真实用户)
  257. dispatch_async(dispatch_get_main_queue(), ^{
  258. [PublicObj updatePushId:registrationID];
  259. });
  260. }];
  261. }
  262. #pragma mark - 点击通知进入app调用此方法 开始
  263. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  264. NSLog(@"userInfo === %@",userInfo);
  265. NSString *contentStr = @"";
  266. if ([[userInfo valueForKey:@"aps"] isKindOfClass:[NSDictionary class]]) {
  267. NSDictionary *apsDic = [userInfo valueForKey:@"aps"];
  268. if ([[apsDic valueForKey:@"alert"] isKindOfClass:[NSDictionary class]]) {
  269. NSDictionary *alertDic = [apsDic valueForKey:@"alert"];
  270. contentStr = minstr([alertDic valueForKey:@"body"]);
  271. }else{
  272. contentStr = minstr([apsDic valueForKey:@"alert"]);
  273. }
  274. }
  275. if(application.applicationState == UIApplicationStateActive) {
  276. [[EBBannerView bannerWithBlock:^(EBBannerViewMaker *make) {
  277. make.content = contentStr;//minstr([[userInfo valueForKey:@"aps"] valueForKey:@"alert"]);
  278. make.object = userInfo;
  279. }] show];
  280. }else {
  281. [self clickNoti:userInfo];
  282. [JPUSHService handleRemoteNotification:userInfo];
  283. }
  284. completionHandler(UIBackgroundFetchResultNewData);
  285. }
  286. -(void)bannerDidClick:(NSNotification *)notifi {
  287. NSDictionary *userInfo = [notifi object];
  288. [self clickNoti:userInfo];
  289. }
  290. -(void)clickNoti:(NSDictionary *)userInfo {
  291. YBWeakSelf;
  292. NSString *not_type = minstr([userInfo valueForKey:@"type"]);
  293. NSDictionary *not_dic = [NSDictionary dictionary];
  294. //获取推送详情---> 发布视频:1 直播开播:2;
  295. if ([not_type isEqual:@"1"] && [[userInfo valueForKey:@"videoinfo"] isKindOfClass:[NSDictionary class]]) {
  296. not_dic = [userInfo valueForKey:@"videoinfo"];
  297. }
  298. if ([not_type isEqual:@"2"] && [[userInfo valueForKey:@"userinfo"] isKindOfClass:[NSDictionary class]]) {
  299. not_dic = [userInfo valueForKey:@"userinfo"];
  300. }
  301. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isLiveing"]) {
  302. [MBProgressHUD showPop:YZMsg(@"正在直播中,无法退出")];
  303. return;
  304. }
  305. //需求:只有是视频的时候处理,直播去首页
  306. if ([not_type isEqual:@"1"]) {
  307. [YBGetVideoObj lookManeger].fromWhere = @"AppNoti";
  308. [YBGetVideoObj lookManeger].videoID = minstr([not_dic valueForKey:@"videoid"]);
  309. [YBGetVideoObj lookManeger].playIndex = 0;
  310. [YBGetVideoObj lookManeger].videoList = @[].mutableCopy;
  311. [YBGetVideoObj lookManeger].paging = 1;
  312. [YBGetVideoObj lookManeger].baseUrl = @"";
  313. [[YBGetVideoObj lookManeger]goLookVC];
  314. }
  315. if ([not_type isEqual:@"2"]) {
  316. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isPlaying"]) {
  317. NSDictionary *contentDic = @{@"title":YZMsg(@"提示"),
  318. @"msg":YZMsg(@"是否退出直播间"),
  319. @"left":YZMsg(@"取消"),
  320. @"right":YZMsg(@"确定")};
  321. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  322. if (eventType == 1) {
  323. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isPlaying"];
  324. [weakSelf goHomeUI];
  325. }
  326. }];
  327. }else{
  328. [weakSelf goHomeUI];
  329. }
  330. }
  331. }
  332. -(void)goHomeUI {
  333. [PublicObj resetVC:[[YBTabBarController alloc]initWithAlert:NO]];
  334. }
  335. #pragma mark - 点击通知进入app调用此方法 结束
  336. #pragma mark - 发送位置
  337. -(void)sendLocation {
  338. [QMapServices sharedServices].apiKey = TencentKey;
  339. [[QMSSearchServices sharedServices] setApiKey:TencentKey];
  340. }
  341. #pragma mark - 定位
  342. -(void)sysLocation{
  343. [[RKLBSManager shareManager] startLocation];
  344. }
  345. /*
  346. -(void)sysLocation{
  347. if (!_lbsManager) {
  348. _lbsManager = [[CLLocationManager alloc] init];
  349. [_lbsManager setDesiredAccuracy:kCLLocationAccuracyBest];
  350. _lbsManager.delegate = self;
  351. // 兼容iOS8定位
  352. SEL requestSelector = NSSelectorFromString(@"requestWhenInUseAuthorization");
  353. if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
  354. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  355. UIAlertController *alertContro = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"%@%@%@",YZMsg(@"打开“定位服务”来允许“"),[infoDictionary objectForKey:@"CFBundleDisplayName"],YZMsg(@"确定您的位置")] preferredStyle:UIAlertControllerStyleAlert];
  356. UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:YZMsg(@"设置") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  357. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  358. }];
  359. [alertContro addAction:cancleAction];
  360. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  361. }];
  362. [alertContro addAction:sureAction];
  363. [self.window.rootViewController presentViewController:alertContro animated:YES completion:nil];
  364. }else{
  365. if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined && [_lbsManager respondsToSelector:requestSelector]) {
  366. [_lbsManager requestWhenInUseAuthorization]; //调用了这句,就会弹出允许框了.
  367. } else {
  368. [_lbsManager startUpdatingLocation];
  369. }
  370. }
  371. }
  372. }
  373. - (void)stopLbs {
  374. [_lbsManager stopUpdatingHeading];
  375. _lbsManager.delegate = nil;
  376. _lbsManager = nil;
  377. }
  378. - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
  379. if (status == kCLAuthorizationStatusRestricted || status == kCLAuthorizationStatusDenied) {
  380. [self stopLbs];
  381. } else {
  382. [_lbsManager startUpdatingLocation];
  383. }
  384. }
  385. - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
  386. [self stopLbs];
  387. }
  388. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
  389. CLLocation *newLocatioin = locations[0];
  390. NSString* locationLat = [NSString stringWithFormat:@"%f",newLocatioin.coordinate.latitude];
  391. NSString* locationLng = [NSString stringWithFormat:@"%f",newLocatioin.coordinate.longitude];
  392. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  393. [geocoder reverseGeocodeLocation:newLocatioin completionHandler:^(NSArray *placemarks, NSError *error) {
  394. if (!error) {
  395. CLPlacemark *placeMark = placemarks[0];
  396. NSString *city = placeMark.locality;
  397. [cityDefault saveLocationLat:locationLat];
  398. [cityDefault saveLocationLng:locationLng];
  399. [cityDefault saveLocationCity:city];
  400. }
  401. }];
  402. [self stopLbs];
  403. }
  404. */
  405. #pragma mark - 分享
  406. -(void)thirdPlant{
  407. [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
  408. [platformsRegister setupQQWithAppId:QQAppId appkey:QQAppKey enableUniversalLink:NO universalLink:QQUniversalLink];
  409. [platformsRegister setupWeChatWithAppId:WechatAppId appSecret:WechatAppSecret universalLink:WechatUniversalLink];
  410. }];
  411. }
  412. #pragma makr - 支付
  413. // NOTE: 9.0以后使用新API接口
  414. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
  415. [OpenInstallSDK handLinkURL:url];
  416. if ([url.scheme localizedCaseInsensitiveCompare:@"com.yunbao.1v1.payments"] == NSOrderedSame) {
  417. return [BTAppSwitch handleOpenURL:url options:options];
  418. }
  419. // if ([url.scheme localizedCaseInsensitiveCompare:@"hailongFengbao.payments"] == NSOrderedSame) {
  420. // return [BTAppSwitch handleOpenURL:url options:options];
  421. // }
  422. if ([url.host isEqualToString:@"safepay"]) {
  423. // 支付跳转支付宝钱包进行支付,处理支付结果
  424. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  425. NSLog(@"result = %@",resultDic);
  426. [[NSNotificationCenter defaultCenter]postNotificationName:@"aliPayNot" object:nil userInfo:resultDic];
  427. }];
  428. // 授权跳转支付宝钱包进行支付,处理支付结果
  429. [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) {
  430. NSLog(@"result = %@",resultDic);
  431. // 解析 auth code
  432. NSString *result = resultDic[@"result"];
  433. NSString *authCode = nil;
  434. if (result.length>0) {
  435. NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  436. for (NSString *subResult in resultArr) {
  437. if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
  438. authCode = [subResult substringFromIndex:10];
  439. break;
  440. }
  441. }
  442. }
  443. NSLog(@"授权结果 authCode = %@", authCode?:@"");
  444. }];
  445. }else if ([url.host isEqual:@"pay"]){
  446. return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self];
  447. }
  448. return YES;
  449. }
  450. -(void)onResp:(BaseResp *)resp{
  451. //支付返回结果,实际支付结果需要去微信服务器端查询
  452. NSString *strMsg;
  453. NSString *code;
  454. switch (resp.errCode) {
  455. case WXSuccess:{
  456. code = @"1";
  457. strMsg = YZMsg(@"支付成功");
  458. NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode);
  459. }break;
  460. case WXErrCodeUserCancel:{
  461. code = @"0";
  462. strMsg = YZMsg(@"支付取消");
  463. NSLog(@"支付取消,retcode = %d", resp.errCode);
  464. }break;
  465. default:{
  466. code = @"-1";
  467. strMsg = YZMsg(@"支付失败");
  468. NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr);
  469. }break;
  470. }
  471. NSDictionary *dic = @{
  472. @"msg":strMsg,
  473. @"code":code
  474. };
  475. [[NSNotificationCenter defaultCenter] postNotificationName:@"wxPayNot" object:nil userInfo:dic];
  476. }
  477. #pragma mark - 启动图版本号、版权信息
  478. -(void)setVersionInfo {
  479. UIImageView *launchImageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
  480. launchImageView.image = [PublicObj getLaunchImage];
  481. [self.window addSubview:launchImageView];
  482. [self.window bringSubviewToFront:launchImageView];
  483. UILabel *copyright = [[UILabel alloc]init];
  484. copyright.text = copyrightDes;
  485. copyright.font = SYS_Font(10);
  486. copyright.textAlignment = NSTextAlignmentCenter;
  487. copyright.textColor = [UIColor whiteColor];
  488. [launchImageView addSubview:copyright];
  489. [copyright mas_makeConstraints:^(MASConstraintMaker *make) {
  490. make.width.mas_equalTo(launchImageView.mas_width);
  491. make.height.mas_equalTo(20);
  492. make.bottom.mas_equalTo(launchImageView.mas_bottom).offset(-10-ShowDiff/2);
  493. make.centerX.mas_equalTo(launchImageView.mas_centerX);
  494. }];
  495. UILabel *vesionLabel = [[UILabel alloc] init];
  496. //获取当前设备中应用的版本号
  497. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  498. //NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];//大版本
  499. NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];//小版本
  500. NSString *app_Name = [infoDic objectForKey:@"CFBundleDisplayName"];
  501. vesionLabel.text = [NSString stringWithFormat:@"%@ V %@",app_Name,currentVersion];
  502. vesionLabel.font = SYS_Font(10);
  503. vesionLabel.textColor = copyright.textColor;
  504. vesionLabel.textAlignment = NSTextAlignmentCenter;
  505. [launchImageView addSubview:vesionLabel];
  506. [vesionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  507. make.width.mas_equalTo(launchImageView.mas_width);
  508. make.height.mas_equalTo(20);
  509. make.bottom.mas_equalTo(copyright.mas_bottom).offset(-20);
  510. make.centerX.mas_equalTo(launchImageView.mas_centerX);
  511. }];
  512. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  513. [UIView animateWithDuration:0.5 animations:^{
  514. launchImageView.alpha = 0.0;
  515. launchImageView.transform = CGAffineTransformMakeScale(1.2, 1.2);
  516. } completion:^(BOOL finished) {
  517. [launchImageView removeFromSuperview];
  518. }];
  519. });
  520. }
  521. #pragma mark - 音视频操作 开始
  522. -(void)startUpload {
  523. YBWeakSelf;
  524. [[YBStorageObj storageManeger]getCOSType:^(int code) {
  525. if (code == 0) {
  526. [weakSelf startUploadOOOOOO];
  527. }
  528. }];
  529. }
  530. -(void)startUploadOOOOOO {
  531. [self resetProgress];
  532. _coverRatio = 1.778;
  533. if (_originalCover) {
  534. CGFloat fixelW = CGImageGetWidth(_originalCover.CGImage);
  535. CGFloat fixelH = CGImageGetHeight(_originalCover.CGImage);
  536. _coverRatio = fixelH/fixelW;
  537. }
  538. dispatch_group_t group = dispatch_group_create();
  539. dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
  540. dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  541. YBWeakSelf;
  542. //原始图片
  543. dispatch_group_async(group, queue, ^{
  544. UIImage *saveImg = _originalCover;
  545. [[NSNotificationCenter defaultCenter]postNotificationName:@"uploadCoverNot" object:saveImg];
  546. NSString *imageName = [PublicObj getNameBaseCurrentTime:@"_origin.png"];
  547. [[YBStorageObj storageManeger]yb_storageImg:saveImg andName:imageName progress:^(CGFloat percent) {
  548. _originalCoverPro = percent;
  549. [weakSelf ybUploadProgress];
  550. }complete:^(int code, NSString *key) {
  551. _cosFinishCoverPath = minstr(key);
  552. dispatch_semaphore_signal(semaphore);
  553. }];
  554. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  555. });
  556. //原始视频
  557. dispatch_group_async(group, queue, ^{
  558. NSString *videoName = [PublicObj getNameBaseCurrentTime:@"_origin.mp4"];
  559. NSString *videoPath = _originalVdieoPath;
  560. [[YBStorageObj storageManeger]yb_storageVideoOrVoice:videoPath andName:videoName progress:^(CGFloat percent) {
  561. _originalVideoPro = percent;
  562. [weakSelf ybUploadProgress];
  563. }complete:^(int code, NSString *key) {
  564. _cosFinishVideoPath = minstr(key);
  565. dispatch_semaphore_signal(semaphore);
  566. }];
  567. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  568. });
  569. //水印视频
  570. if (_originalMKVideoPath) {
  571. _uploadNum = 3;
  572. dispatch_group_async(group, queue, ^{
  573. NSString *videoName = [PublicObj getNameBaseCurrentTime:@"_water.mp4"];
  574. [[YBStorageObj storageManeger]yb_storageVideoOrVoice:_originalMKVideoPath andName:videoName progress:^(CGFloat percent) {
  575. _mkVideoPro = percent;
  576. [weakSelf ybUploadProgress];
  577. }complete:^(int code, NSString *key) {
  578. _cosFinishMKVideoPath = minstr(key);
  579. dispatch_semaphore_signal(semaphore);
  580. }];
  581. dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
  582. });
  583. }
  584. dispatch_group_notify(group, queue, ^{
  585. dispatch_async(dispatch_get_main_queue(), ^{
  586. [weakSelf resetProgress];
  587. [weakSelf requstAPPServceTitle:_videoTitle andVideo:_cosFinishVideoPath andImage:_cosFinishCoverPath andWaterName:_cosFinishMKVideoPath];
  588. });
  589. NSLog(@"任务完成执行");
  590. });
  591. }
  592. -(void)resetProgress {
  593. _originalVideoPro = 0.0;
  594. _originalCoverPro = 0.0;
  595. _mkVideoPro = 0.0;
  596. _uploadNum = 2;
  597. _allUploadPro = 0.0;
  598. }
  599. -(void)ybUploadProgress{
  600. _allUploadPro = (_originalCoverPro+_originalVideoPro+_mkVideoPro)/_uploadNum;
  601. NSLog(@"allll:%f",_allUploadPro);
  602. [[NSNotificationCenter defaultCenter]postNotificationName:@"uploadProNot" object:@(_allUploadPro)];
  603. }
  604. #pragma mark - 上传七牛或者腾讯云存储成功后把视频地址、封面地址反馈给自己的服务器
  605. -(void)requstAPPServceTitle:(NSString *)myTile andVideo:(NSString *)video andImage:(NSString *)image andWaterName:(NSString *)water {
  606. if ([PublicObj checkNull:_cosFinishVideoPath] || [PublicObj checkNull:_cosFinishCoverPath] || (![PublicObj checkNull:_originalMKVideoPath] && [PublicObj checkNull:_cosFinishMKVideoPath])) {
  607. [MBProgressHUD hideHUD];
  608. [MBProgressHUD showPop:@"发布失败"];
  609. return;
  610. }
  611. YBWeakSelf;
  612. // NSString *videoClassID = [PublicObj checkNull:minstr([_videoClassDic valueForKey:@"id"])]?@"0":minstr([_videoClassDic valueForKey:@"id"]);
  613. NSMutableDictionary *pullDic = @{
  614. @"uid":[Config getOwnID],
  615. @"token":[Config getOwnToken],
  616. @"title":minstr(myTile),
  617. @"href":minstr(video),
  618. @"thumb":minstr(image),
  619. @"lng":[NSString stringWithFormat:@"%@",[cityDefault getLocationLng]],
  620. @"lat":[NSString stringWithFormat:@"%@",[cityDefault getLocationLat]],
  621. @"city":[NSString stringWithFormat:@"%@",[cityDefault getLocationCity]?[cityDefault getLocationCity]:@"好像在火星"],
  622. @"music_id":_musicID ? _musicID : @"0",
  623. @"labelid":_topicID ? _topicID:@"0",
  624. //@"goodsinfo": _shopJsonStr ?_shopJsonStr:@"",
  625. @"goodsid":_goodsID,
  626. @"href_w":water?water:@"",
  627. @"classid":_videoClassID ?_videoClassID:@"" ,
  628. @"coin":_videoChargeNum?_videoChargeNum:@"0",
  629. @"anyway":[NSString stringWithFormat:@"%.3f",_coverRatio],
  630. @"is_userad":_is_userad,
  631. @"userad_url":_userad_url,
  632. @"activeid":_activeId?_activeId:@"",
  633. }.mutableCopy;
  634. [YBNetworking postWithUrl:@"Video.setVideo" Dic:pullDic Suc:^(int code, id info, NSString *msg) {
  635. if (code == 0) {
  636. [MBProgressHUD hideHUD];
  637. /*
  638. NSString *audit_switch = [NSString stringWithFormat:@"%@",[common getAuditSwitch]];
  639. if ([audit_switch isEqual:@"1"]) {
  640. [MBProgressHUD showSuccess:@"上传成功,请等待审核"];
  641. }else{
  642. [MBProgressHUD showSuccess:@"发布成功"];
  643. }
  644. */
  645. NSString *audit_switch = [NSString stringWithFormat:@"%@",[common getAuditSwitch]];
  646. if ([audit_switch isEqual:@"1"]) {
  647. [MBProgressHUD showSuccess:YZMsg(@"上传成功,请等待审核")];
  648. }else{
  649. BOOL isOk = [[NSFileManager defaultManager] removeItemAtPath:_originalVdieoPath error:nil];
  650. if (_originalMKVideoPath) {
  651. [[NSFileManager defaultManager] removeItemAtPath:_originalMKVideoPath error:nil];
  652. }
  653. NSLog(@"%d shanchushanchushanchu",isOk);
  654. NSDictionary *infoDic = [info firstObject];
  655. NSLog(@"====%@",infoDic);
  656. dispatch_async(dispatch_get_main_queue(), ^{
  657. [weakSelf uploadSuc:infoDic];
  658. });
  659. }
  660. }else {
  661. [MBProgressHUD hideHUD];
  662. [MBProgressHUD showError:msg];
  663. }
  664. } Fail:^(id fail) {
  665. [MBProgressHUD hideHUD];
  666. [MBProgressHUD showError:@"网络连接断开,视频上传失败"];
  667. }];
  668. }
  669. -(void)uploadSuc:(NSDictionary *)dic {
  670. NSString *showSharePop = minstr([[NSUserDefaults standardUserDefaults]objectForKey:@"show_share_pop"]);
  671. UIApplicationState state = [UIApplication sharedApplication].applicationState;
  672. NSArray *shareA = [NSArray arrayWithArray:[common share_type]];
  673. if (state != UIApplicationStateActive || ![showSharePop isEqual:@"1"] || shareA.count<=0){
  674. return;
  675. }
  676. //分享
  677. NSString *videoId = minstr([dic valueForKey:@"id"]);
  678. NSString * imageThumb = minstr([dic valueForKey:@"thumb_s"]);
  679. NSString *videoTitle = minstr([dic valueForKey:@"title"]);
  680. NSString *shareDes = [common video_share_des];
  681. if (![PublicObj checkNull:videoTitle]) {
  682. shareDes = videoTitle;
  683. }
  684. NSDictionary *shareDic = @{@"id":videoId,@"thumb_s":imageThumb,@"publish_des":shareDes,@"userinfo":@{@"user_nickname":[Config getOwnNicename]}};
  685. [YBShareView showMidPopShareType:RKShareType_VPMidPop parameter:shareDic commplete:^(int codeEvent, NSString *nums) {
  686. }];
  687. }
  688. #pragma mark - 音视频操作结束
  689. //通过openInstall获取已经安装App被唤醒时的参数(如果是通过渠道页面唤醒App时,会返回渠道编号)
  690. -(void)getWakeUpParams:(OpeninstallData *)appData{
  691. if (appData.data) {//(动态唤醒参数)
  692. //e.g.如免填邀请码建立邀请关系、自动加好友、自动进入某个群组或房间等
  693. }
  694. if (appData.channelCode) {//(通过渠道链接或二维码唤醒会返回渠道编号)
  695. //e.g.可自己统计渠道相关数据等
  696. }
  697. NSLog(@"OpenInstallSDK:\n动态参数:%@;\n渠道编号:%@",appData.data,appData.channelCode);
  698. }
  699. // 统一接收消息的回调
  700. /// @param notification 消息对象(有2种类型NSDictionary和UNNotification具体解析参考示例代码)
  701. /// @note 此回调为前台收到通知消息及所有状态下收到静默消息的回调(消息点击需使用统一点击回调)
  702. /// 区分消息类型说明:xg字段里的msgtype为1则代表通知消息msgtype为2则代表静默消息
  703. - (void)xgPushDidReceiveRemoteNotification:(nonnull id)notification withCompletionHandler:(nullable void (^)(NSUInteger))completionHandler{
  704. if ([notification isKindOfClass:[UNNotificationResponse class]]) {
  705. NSLog(@"aaaaaaaaaaa[TPNS Demo] click notification: %@", ((UNNotificationResponse *)notification).notification.request.content.userInfo);
  706. } else if ([notification isKindOfClass:[NSDictionary class]]) {
  707. NSLog(@"bbbbbbbbb[TPNS Demo] click notification: %@", notification);
  708. }
  709. /// code
  710. }
  711. /// 统一点击回调
  712. /// @param response 如果iOS 10+/macOS 10.14+则为UNNotificationResponse,低于目标版本则为NSDictionary
  713. - (void)xgPushDidReceiveNotificationResponse:(nonnull id)response withCompletionHandler:(nonnull void (^)(void))completionHandler {
  714. if ([response isKindOfClass:[UNNotificationResponse class]]) {
  715. NSLog(@"[TPNS Demo] click notification: %@", ((UNNotificationResponse *)response).notification.request.content.userInfo);
  716. NSDictionary *responeDic = ((UNNotificationResponse *)response).notification.request.content.userInfo;
  717. NSDictionary *userInfo =[PublicObj dictionaryWithJsonString:minstr([responeDic valueForKey:@"custom"])];
  718. if ([minstr([userInfo valueForKey:@"type"]) isEqual:@"1"]) {
  719. // if([[userInfo valueForKey:@"userinfo"] valueForKey:@"uid"] != nil)
  720. // {
  721. // [[NSNotificationCenter defaultCenter] postNotificationName:@"jinruzhibojiantongzhi" object:[userInfo valueForKey:@"userinfo"]];
  722. // }
  723. }else if ([minstr([userInfo valueForKey:@"type"]) isEqual:@"2"]) {
  724. // [[NSNotificationCenter defaultCenter] postNotificationName:@"system_notification" object:nil];
  725. // [self goMsgVC];
  726. }
  727. } else if ([response isKindOfClass:[NSDictionary class]]) {
  728. NSLog(@"[TPNS Demo] click notification: %@", response);
  729. }
  730. /// code
  731. }
  732. /**
  733. @brief 注册推送服务回调
  734. @param deviceToken APNs 生成的 Device Token
  735. @param xgToken TPNS 生成的 Token,推送消息时需要使用此值。TPNS 维护此值与 APNs 的 Device Token 的映射关系
  736. @param error 错误信息,若 error 为 nil 则注册推送服务成功
  737. @note TPNS SDK1.2.6.0+
  738. */
  739. - (void)xgPushDidRegisteredDeviceToken:(nullable NSString *)deviceToken xgToken:(nullable NSString *)xgToken error:(nullable NSError *)error{
  740. NSLog(@"xgToken------:%@ ---errror:%@",xgToken, error);
  741. if ([Config getOwnID]) {
  742. [[XGPushTokenManager defaultTokenManager] upsertAccountsByDict:@{@(0):[Config getOwnID]}];
  743. }
  744. }
  745. /// 注册推送服务失败回调
  746. /// @param error 注册失败错误信息
  747. /// @note TPNS SDK1.2.7.1+
  748. -(void)xgPushDidFailToRegisterDeviceTokenWithError:(nullable NSError *)error {
  749. }
  750. @end