123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- //
- // LaunchRequest.m
- // FirstLink
- //
- // Created by ascii on 15/8/21.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FKLaunchRequest.h"
- #import "FKLaunchStore.h"
- #import "UserDefaultManager.h"
- #import "FKRegisterTipView.h"
- #import "FKWindowViewManager.h"
- #import "FKDynamicMessageItem.h"
- #import "FKRecommendReform.h"
- #import "FLControllerHelper.h"
- #import "SchemaManager.h"
- @implementation FKLaunchRequest
- + (void)requestLaunchUpdateWithInterval:(NSTimeInterval)interval {
- [NSTimer scheduledTimerWithTimeInterval:interval
- target:[FKLaunchRequest class]
- selector:@selector(requestLaunchUpdate)
- userInfo:nil
- repeats:NO];
- }
- + (void)requestLaunchUpdate {
- NSString *remoteLaunchURL = [FKLaunchStore remoteLaunchImageURL];
- NSString *encodeLaunchURL = @"";
- if (remoteLaunchURL) {
- encodeLaunchURL = [remoteLaunchURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- }
-
- NSString *URLString = [NSString stringWithFormat:@"%@/link-site/api/initpic.json?pic_url=%@"
- ,[[FKServerUtil sharedInstance] apiServer]
- ,encodeLaunchURL];
-
- FLDataCenter *dataCenter = [FLDataCenter sharedDataCenter];
- [dataCenter POST:URLString
- parameters:[FLRequestHelper commonParamaterForLogin]
- success:^(MSGHeader *header, id responseObject)
- {
- if (header.code.intValue == RESPONSE_MSG_NORMAL) {
- [FKLaunchRequest parseLaunchResponse:responseObject];
- }
- } failure:^(MSGHeader *header, NSError *error) {
- }];
- }
- + (void)parseLaunchResponse:(NSDictionary *)json {
- NSString *imageURL = [FKLaunchRequest parseLaunchImageURL:json];
- NSString *localRemoteURL = [FKLaunchStore remoteLaunchImageURL];
- NSString *targetURL = [FKLaunchRequest parseLaunchTargetURL:json];
-
- if (!imageURL || imageURL.length == 0) {
- [FKLaunchStore removeNetLaunchImage];
- [[UserDefaultManager sharedManager] removeUserDefaultKey:LAUNCH_TARGET_URL_KEY];
- return;
- }
-
- if (imageURL && ![imageURL isEqualToString:localRemoteURL]) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- if (imageURL.length > 0) {
- NSURL *url = [NSURL URLWithString:imageURL];
- UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
-
- if (image && imageURL) {
- [FKLaunchStore removeNetLaunchImage];
- [FKLaunchStore saveNetLaunchImage:image name:imageURL];
-
- [[UserDefaultManager sharedManager] setUserDefaultObject:targetURL key:LAUNCH_TARGET_URL_KEY];
- } else {
- [FKLaunchStore removeNetLaunchImage];
- [[UserDefaultManager sharedManager] removeUserDefaultKey:LAUNCH_TARGET_URL_KEY];
- }
- }
- });
- } else {
- [[UserDefaultManager sharedManager] setUserDefaultObject:targetURL key:LAUNCH_TARGET_URL_KEY];
- }
- }
- + (NSString *)parseLaunchImageURL:(NSDictionary *)json {
- if (json[@"data"] != [NSNull null]) {
- if (IS_IPHONE_4 && json[@"data"][@"pic"][@"img_1"] != [NSNull null]) {
- return [NSString stringWithFormat:@"%@", json[@"data"][@"pic"][@"img_1"]];
- } else if (json[@"data"][@"pic"][@"img_2"] != [NSNull null]) {
- return [NSString stringWithFormat:@"%@", json[@"data"][@"pic"][@"img_2"]];
- }
- }
- return nil;
- }
- + (NSString *)parseLaunchTargetURL:(NSDictionary *)json {
- if (json[@"data"][@"pic"][@"target_url"] != [NSNull null]) {
- return [NSString stringWithFormat:@"%@", json[@"data"][@"pic"][@"target_url"]];
- }
- return nil;
- }
- + (void)requestOperationAlertInfo {
- NSString *URLString = [NSString stringWithFormat:@"%@/link-site/api/cash_coupon/find_messages.json", [[FKServerUtil sharedInstance] apiServer]];
-
- [[FLDataCenter sharedDataCenter] POST:URLString parameters:[FLRequestHelper commonParamater] success:^(MSGHeader *header, id responseObject) {
- if (header.code.intValue == RESPONSE_MSG_NORMAL) {
- FKDynamicMessageItem *item = [FKRecommendReform parserDynamicItemWithDict:responseObject];
- if (item.freshPic.length) {
- [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:item.freshPic] options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
- if (image && [[FKWindowViewManager sharedManager] isNeedShowRegisterTip]) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
- CGFloat width = 250, height = 350;
- FKRegisterTipView *view = [[FKRegisterTipView alloc] initWithBgImg:image];
- view.frame = CGRectMake((UISCREENWIDTH-width)/2, (UISCREENHEIGH-height)/2, width, height);
- view.completeAction = ^() {
- [[FKWindowViewManager sharedManager] completeShowRegisterTip];
- [[FKWindowViewManager sharedManager] closeFloatView];
-
- if (item.targetURL.length > 0) {
- [[SchemaManager sharedManager] parserURL:[NSURL URLWithString:item.targetURL] shouldCache:YES];
- } else {
- [FLControllerHelper presentLoginViewController];
- }
- };
- [[FKWindowViewManager sharedManager] appendFloatView:view];
- });
- }
- }];
- }
- }
- } failure:^(MSGHeader *header, NSError *error) {
-
- }];
- }
- @end
|