Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 后台performFetchWithCompletionHandler使用块导致崩溃_Ios_Objective C_Objective C Blocks_Background Process - Fatal编程技术网

Ios 后台performFetchWithCompletionHandler使用块导致崩溃

Ios 后台performFetchWithCompletionHandler使用块导致崩溃,ios,objective-c,objective-c-blocks,background-process,Ios,Objective C,Objective C Blocks,Background Process,我有一个应用程序,可以成功获取并显示RSS提要,我想添加后台获取。我收到:线程1执行错误访问(代码=1,地址=0x10),如下所示 应用程序内代理: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //setup background fetch [application setMinimumBackgroundFe

我有一个应用程序,可以成功获取并显示RSS提要,我想添加后台获取。我收到:线程1执行错误访问(代码=1,地址=0x10),如下所示

应用程序内代理:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //setup background fetch
[application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];

return YES;
}

在我的主ViewController中:

@property (nonatomic, copy) void (^completionHandler)(BOOL);
- (void) fetchNewDataWithCompletionHandler: (void (^)(UIBackgroundFetchResult))completionHandler;
- (void) startParsingWithCompletionHandler:(void (^)(BOOL))completionHandler;

-(void)fetchNewDataWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{

self.completionHandler = UIBackgroundFetchResultNewData; //completionHandler;
[self startParsingWithCompletionHandler:^(BOOL success){

    if (success) {
        completionHandler(UIBackgroundFetchResultNewData);
        NSLog(@"completionHandler");
    }
    else{
        NSLog(@"error");
    }
}];
}

我收到的输出是:

performFetchWithCompletionHandler

回电

self.completionHandler = UIBackgroundFetchResultNewData; 
不匹配类型
completionHandler
的类型为
(void(^)(UIBackgroundFetchResult))
,而
UIBackgroundFetchResultNewData
的类型为
NSUInteger

typedef enum : NSUInteger {
   UIBackgroundFetchResultNewData,
   UIBackgroundFetchResultNoData,
   UIBackgroundFetchResultFailed 
} UIBackgroundFetchResult;
因此,当您调用
self.completionHandler(YES)
时,
self.completionHandler
是一个
nsuiger
,因此
nsuiger(YES)
没有多大意义。

尝试以下方法: 创建变量var completionHandler:((UIBackgroundFetchResult)->Void)! 当您收到推送通知集时

self.completionHandler = completionHandler.
然后做你的后台工作,通常从服务器下载新数据。 完成此操作后,按如下方式调用completionHandler:

if let handler = self.completionHandler{
    UIBackgroundFetchResult.NewData
}
self.completionHandler = nil

那么你应该摆脱这个警告。

谢谢。这解决了崩溃问题,但现在receive:Warning:Application delegate收到了对-Application:performFetchWithCompletionHandler:的调用,但从未调用过完成处理程序。self.completionHandler=UIBackgroundFetchResultNewData;修复了崩溃,但解决了崩溃,但现在接收:警告:应用程序委托接收到对-Application:performFetchWithCompletionHandler:的调用,但从未调用完成处理程序。我发现self.completionHandler==nil,当它到达storyistone方法时
self.completionHandler = completionHandler.
if let handler = self.completionHandler{
    UIBackgroundFetchResult.NewData
}
self.completionHandler = nil