开发者

NSStream on Background didn't call

开发者 https://www.devze.com 2023-01-31 00:38 出处:网络
- (void)applicationDidEnterBackground:(UIApplication *)application { NSOutputStream *outputStream; NSInputStream *inputStream;
- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSOutputStream *outputStream;
    NSInputStream *inputStream;

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        [inputStream setDelegate:self];
        [outputStream setDelegate:self];

        [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
                               forMode:NSRunLoopCommonModes];
        [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
                                forMode:NSRunLoopCommonModes];

        [app endBackgroundTask:bgTask];

        bgTask = UIBackgroundTaskInvalid;

    开发者_如何转开发});
}

Input,OutputStream delegate didn't call.What i am doing wrong.


Did you run the current run loop by following way ?

 do {

    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]];
  } while (done == TRUE);


You seem to have omitted the streams' initialization, e.g.

NSInputStream *inputStream = [NSInputStream inputStreamWithURL: myURL];
NSOutputStream *outputStream = [NSOutputStream outputStreamToMemory];
0

精彩评论

暂无评论...
验证码 换一张
取 消