IOS报亭背景故障排除

我正在开始一个报摊应用程序,首先我要testing所有的框架,看看谁的一切正常。 我已经在前台下载了通知触发的问题。 但我不知道如何在后台下载,或者至less我失去了一些东西…这是我添加到plist的东西: plist中

该应用程序的目标是IOS 5 …这是我的代码…当然,我也实现了NKAsset的三种URLConection方法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]; } } 

}

我错过了什么,也有额外的不必要的代码? 请帮忙。

  • 如果您正在testing应用程序(在将其滑开之后),并在iOS7上提供内容可用:1的通知,则会出现一个错误:请阅读此处 和此处(使用您的开发人员帐户login) 。 它应该在iOS 5-6上工作,如果你有一个设备来testing还没有更新。

  • 您还需要Info.plist中的一个键: 所需的背景模式 – 报摊内容

  • 最后在你的代码中,我认为你应该改变一下你的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 }