IOS报亭背景故障排除

时间:2013-12-24 17:56:51

标签: ios objective-c push-notification background-process newsstand-kit

我正在启动报亭应用程序,首先我正在测试所有框架以查看一切正常。我已经在前台下载了一个由通知触发的问题。但我不知道如何在后台下载,或者至少我错过了一些东西......这是我添加到plist中的东西: plist

该应用针对IOS 5 ...这是我的代码...当然我也实现了NKAssetDownload的三种URLConection方法

    - (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];
    }
}

}

我缺少什么,还有额外的不必要代码吗?请帮忙。

1 个答案:

答案 0 :(得分:1)

  • 如果您正在测试使用iOS7上的content-available:1通知来唤醒应用程序(刷完之后),则会出现错误:read here and here (log in with your dev account)。 它应该适用于iOS 5-6,如果你有一个尚未更新的测试设备。

  • 您还需要Info.plist中的密钥:Required background modes - newsstand-content

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