IOS Newsstand background troubleshouting

断了今生、忘了曾经 提交于 2019-12-08 09:39:51

问题


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:

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.


回答1:


  • 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.

  • You also need a key in the Info.plist: Required background modes - newsstand-content

  • 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
    
    }
    


来源:https://stackoverflow.com/questions/20764967/ios-newsstand-background-troubleshouting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!