iOS 8 Crash NSURLSessionTaskPriorityHigh

iOS 8 Crash NSURLSessionTaskPriorityHigh

在启动时候如果在iOS8上使用了这个API会直接导致Crash;

错误日志:

dyld: Symbol not found:_NSURLSessionTaskPriorityHigh

下面是解决办法

Short story: I get this error when launching the app on iOS 8.0. The app targets iOS 8+. There is no error if it runs on iOS 9 and 10. The app is built using XCode 8.1 (8B62). It occurs right on application launch - no app code is executed.

Long story: I've received reports that when the app is built using the build server it crashes immediately on iOS 8.x. I've built the app locally using same configuration but couldn't reproduce the issue. Then I've downloaded the XCode project (it's a Unity based app - project is generated as a part of the build process) from build server. Using this project I've reproduced the issue. What I don't understand is that from that time all my local builds are also broken as if the downloaded project "infected" my system;)

I've tried a few things to fix it (ideas from stackoverflow):

\1. Remove and add the Foundation framework,

\2. Move the Foundation framework before CFNetwork

\3. Set the CFNetwork framework as optional

\4. Delete XCode Derived Data.

I've also checked if the missing symbol exists in the Foundation framework and I've found it in Foundation.tbd and in NSURLSession.h (without the leading underscore).

Well, the solutions is to move CFNetwork BEFORE the Foundation framework.

官方文档上标示是在iOS 8 是可以使用此API

/*
 * Sets a scaling factor for the priority of the task. The scaling factor is a
 * value between 0.0 and 1.0 (inclusive), where 0.0 is considered the lowest
 * priority and 1.0 is considered the highest.
 *
 * The priority is a hint and not a hard requirement of task performance. The
 * priority of a task may be changed using this API at any time, but not all
 * protocols support this; in these cases, the last priority that took effect
 * will be used.
 *
 * If no priority is specified, the task will operate with the default priority
 * as defined by the constant NSURLSessionTaskPriorityDefault. Two additional
 * priority levels are provided: NSURLSessionTaskPriorityLow and
 * NSURLSessionTaskPriorityHigh, but use is not restricted to these.
 */
@property float priority API_AVAILABLE(macos(10.10), ios(8.0), watchos(2.0), tvos(9.0));

我自己的处理逻辑是这样的

//.h
typedef NS_ENUM(NSInteger, SQSNRequestPriority) {
    SQSNRequestPriorityLow = -4L,
    SQSNRequestPriorityDefault = 0,
    SQSNRequestPriorityHigh = 4,
};

//------------

if ([requestTask respondsToSelector:@selector(priority)]) {
        switch (priority) {
            case SQSNRequestPriorityHigh:
                requestTask.priority = 0.75; // NSURLSessionTaskPriorityHigh
                break;
            case SQSNRequestPriorityLow:
                requestTask.priority = 0.25; // NSURLSessionTaskPriorityLow
                break;
            case SQSNRequestPriorityDefault:
            default:
                requestTask.priority = 0.5;  // NSURLSessionTaskPriorityDefault
                break;
        }
    }

暂时归于系统BUG吧!

你可能感兴趣的:(iOS 8 Crash NSURLSessionTaskPriorityHigh)