报亭图标不更新

时间:2014-03-08 17:02:40

标签: ios objective-c xcode newsstand-kit

我一直试图解决这个问题超过一个星期,出于某种原因,无论我做什么,报摊图标都没有通过代码更新。

我已阅读Apple开发人员文档,并检查了我的图像尺寸并且它们都是正确的。我甚至去创建了一个新课程,只是为了更新报摊图标。

无论如何,这是我的代码:

#import "NewsstandIcon.h"
#import <NewsstandKit/NewsstandKit.h>
@implementation NewsstandIcon

-(void)setIcon:(NSString *)withURL
{
    // TEMPORARY OVERRIDE
    withURL = @"http://www.imgtag.me/735x1024";

    _downloadedData = [[NSMutableData alloc] init];
    [_downloadedData setLength: 0];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:withURL]];
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    NSLog(@"[ICON DOWNLOAD] Starting download");
}

// DOWNLOAD METHODS
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)response {
    if ([response statusCode] == 404)
    {
        NSLog(@"[ICON DOWNLOAD] Failed - Error 404 - File not found");
        [connection cancel];
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    NSLog(@"[ICON DOWNLOAD] Received Data");
    [_downloadedData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"[ICON DOWNLOAD] Completed. Length %d", [_downloadedData length]);
    [[UIApplication sharedApplication] setNewsstandIconImage: [[UIImage alloc] initWithData: _downloadedData]];

    NSLog(@"[ICON DOWNLOAD] Setting Icon");
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"[ICON DOWNLOAD] Failed - %@", [error description]);
}
@end

这输出:

2014-03-08 16:53:24.308 magazine[3590:70b] [ICON DOWNLOAD] Received Data
2014-03-08 16:53:24.308 magazine[3590:70b] [ICON DOWNLOAD] Completed. Length 12833
2014-03-08 16:53:25.892 magazine[3590:70b] [ICON DOWNLOAD] Setting Icon

我还将下载的图像写入本地文件系统。然后我浏览了文件,图像完整无缺且可读。

正如您在代码中看到的,我暂时覆盖了setIcon方法的withURL参数。我用很多图像尝试了这个,但没有一个能够工作。您可以在我的输出中查看文件大小。

当我调用setNewsstandIcon时,我的输出中没有警告,图标只是保留为默认图标。

非常感谢任何帮助!

感谢。

1 个答案:

答案 0 :(得分:0)

如果您的图标不符合规格,则会生成零图标。看看这个:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/NewsstandIcons.html#//apple_ref/doc/uid/TP40006556-CH28-SW1

注意:记得为视网膜设置尺度为2的uiimage