0

I have inherited some code in xcode (below) and am getting an 'Unexpected '@' in program' error reported.

I have been able to figure out that this is likely to be due to the fact that the original code was written in xcode >9.0 while my version (due to hardware limitations) is xcode 8.2.1

From researching, I have determined that the issue is with this part of the code:

 if (@available(iOS 9.0, *)) {

Which I need to change to

if #available(iOS 9.0, *) {

But if I do that, I then get the following error

Expected '(' after 'if'

The original piece of code is

if ([self.uploadProgress respondsToSelector:@selector(setResumingHandler:)]) {
    if (@available(iOS 9.0, *)) {
        [self.uploadProgress setResumingHandler:^{
            __typeof__(weakTask) strongTask = weakTask;
            [strongTask resume];
        }];
    } else {
        // Fallback on earlier versions
    }
}

And this is what I have tried to change it to

if ([self.uploadProgress respondsToSelector:@selector(setResumingHandler:)]) {
    if #available(iOS 9.0, *) {
        [self.uploadProgress setResumingHandler:^{
            __typeof__(weakTask) strongTask = weakTask;
            [strongTask resume];
        }];
    } else {
        // Fallback on earlier versions
    }
}

Any help would be appreciated, thank you.

omega1
  • 1,031
  • 4
  • 21
  • 41
  • 2
    That's because the one you are using is for Swift, not objective c. Check out this answer: https://stackoverflow.com/questions/3339722/how-to-check-ios-version/44429397#44429397 – Pochi Dec 21 '17 at 08:15
  • 2
    Possible duplicate of [How to check iOS version?](https://stackoverflow.com/questions/3339722/how-to-check-ios-version) – Pochi Dec 21 '17 at 08:15

1 Answers1

2

available(iOS 9.0, *) is used in swift for objective-c you can try this

 if (floor(NSFoundationVersionNumber) >= NSFoundationVersionNumber_iOS_9_x_Max)

OR

#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >=  __IPHONE_10_0
    // For iOS 10 display notification (sent via APNS)

    #endif
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • Thank you, it was the difference between swift/objective-c that I hadn't fully understood. Thanks. – omega1 Dec 21 '17 at 08:20