IOS报亭后台故障排除

标签 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];
    }
}

}

我错过了什么,还有多余的不必要的代码吗?请帮忙。

最佳答案

  • 如果您在 iOS7 上测试使用内容可用:1 通知唤醒应用程序(将其滑开后),它有一个错误:read here and here (log in with your dev account) . 如果您要测试的设备尚未更新,它应该可以在 iOS 5-6 上运行。

  • 您还需要 Info.plist 中的 key :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
    
    }
    

关于IOS报亭后台故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20764967/

相关文章:

ios - 使用 Picker View - setter、getter 混淆的概念

objective-c - 屏幕截图到剪贴板可以在 Cocoa 中使用,但不能保存到文件或新邮件消息中

ios - 放大 UIButton 文本?

ios - 推送通知如何传输到设备?

从 MySQL 数据库获取记录时,php 显示 null

ios - 只需将 Metal frag 着色器设为透明颜色?

ios - UIPageViewController pageIndex 没有正确减少

objective-c - MP Media Player轨道长度显示(xcode)

ios - iOS 推送通知的 MQTT 服务

iOS, CGGradientCreateWithColorComponets 设置RGBA颜色