问题描述
我正在启动一个报亭应用程序,首先我正在测试所有框架以查看谁都能正常工作.在前台时,我已经下载了由通知触发的问题.但是我不知道如何在后台下载,或者至少我缺少一些东西...这是我添加到plist的内容:
I'm starting a newsstand application and first I'm testing all the framework to see who everything works. I already downloaded an issue triggered by a notification when in foreground. but I don't know how to download in background, or at least I'm missing something... Here is the stuff I added to plist:
该应用程序针对IOS 5 ...这是我的代码...当然,我还实现了NKAssetDownload
The app is targeted for IOS 5... here is my code... of course I also implemented the three URLConection methods of NKAssetDownload
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([launchOptions objectForKey:UIApplicationLaunchOptionsNewsstandDownloadsKey] || [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
NKLibrary *nkLib = [NKLibrary sharedLibrary];
for(NKAssetDownload *asset in [nkLib downloadingAssets]) {
[asset downloadWithDelegate:self];
}
}else{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeNewsstandContentAvailability
)];
}
[[NSUserDefaults standardUserDefaults]setBool: YES forKey:@"NKDontThrottleNewsstandContentNotifications"];
[[NSUserDefaults standardUserDefaults] synchronize];
return YES;
}
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(@"didReceiveRemoteNotification");
if (userInfo) {
NKIssue *issue4 = [[NKLibrary sharedLibrary] issueWithName:@"01_Primera"];
if (!issue4) {
issue4= [[NKLibrary sharedLibrary] addIssueWithName:@"01_Primera" date:[NSDate date]];
}
if([issue4 status]==NKIssueContentStatusNone) {
NSURL *downloadURL = [NSURL URLWithString:@"http://www.viggiosoft.com/media/data/blog/newsstand/magazine-4.pdf"];
NSURLRequest *req = [NSURLRequest requestWithURL:downloadURL];
NKAssetDownload *assetDownload = [issue4 addAssetWithRequest:req];
[assetDownload downloadWithDelegate:self];
}
}
}
我缺少什么,还有其他多余的代码吗?请帮忙.
What am I missing, and also do I have extra unnecessary code? please help.
推荐答案
-
如果要在iOS 7上测试带有内容可用:1的通知唤醒应用程序(在将其清除后),则存在错误: 此处(使用您的开发者帐户登录).如果您要测试的设备尚未更新,则它应该可以在iOS 5-6上运行.
If you are testing waking up the app (after swiping it away) with a notification with content-available:1 on iOS7, it has a bug: read here and here (log in with your dev account).It should work on iOS 5-6, if you have a device to test that hasn't been updated.
您还需要在Info.plist中输入密钥:所需的后台模式-报亭内容
You also need a key in the Info.plist: Required background modes - newsstand-content
最后,在代码中,我认为您应该在didFinishLaunchingWithOptions中进行一些更改:
Finally in your code I think you should change a bit in your didFinishLaunchingWithOptions:
if ([launchOptions objectForKey:UIApplicationLaunchOptionsNewsstandDownloadsKey] || [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { [self handleNotification:launchOptions]; } //...other code... //This code can be the same as with didReceiveRemoveNotification -(void) handleNotification:(NSDictionary*)userInfo{ //check userInfo for "content-available" key //if there is content-available:1 check for an issue_id/content_id in the rest of the notification payload (userInfo), and download the issue }
这篇关于iOS报亭后台故障排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!