后台 NSStream 未调用

发布于 2024-10-08 13:26:50 字数 710 浏览 0 评论 0原文

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

    });
}

输入,输出流委托没有调用。我做错了什么。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2024-10-15 13:26:50

您是否通过以下方式运行当前的运行循环?

 do {

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

Did you run the current run loop by following way ?

 do {

    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]];
  } while (done == TRUE);
巾帼英雄 2024-10-15 13:26:50

您似乎省略了流的初始化,例如

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

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

NSInputStream *inputStream = [NSInputStream inputStreamWithURL: myURL];
NSOutputStream *outputStream = [NSOutputStream outputStreamToMemory];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文