Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ARKit as optional framework and SCNHitTestSearchModeAll #166

Open
michbil opened this issue Mar 5, 2018 · 4 comments
Open

Using ARKit as optional framework and SCNHitTestSearchModeAll #166

michbil opened this issue Mar 5, 2018 · 4 comments

Comments

@michbil
Copy link

michbil commented Mar 5, 2018

I'm using ARKit as optional framework for my app.
After recent update i've noticed that app started crashing under iOS 10.

dyld: Symbol not found: _SCNHitTestOptionSearchMode

After some research i've found that problem is caused by selector @(SCNHitTestSearchModeAll).
SCNHitTestSearchModeAll is available only in iOS 11. If i comment selector, everything starting ok.

- (NSDictionary *)getSceneObjectsHitResult:(const CGPoint)tapPoint  {
    NSDictionary *options = @{
                              SCNHitTestRootNodeKey: self.localOrigin,
                              SCNHitTestSortResultsKey: @(YES),
                              SCNHitTestOptionSearchMode: @(SCNHitTestSearchModeAll)
                              };
    NSArray<SCNHitTestResult *> *results = [_arView hitTest:tapPoint options:options];
    NSMutableArray * resultsMapped = [self mapHitResultsWithSceneResults:results];
    NSDictionary *result = getSceneObjectHitResult(resultsMapped, tapPoint);
    return result;
}

What's the best way to isolate this selector? and make it used only in iOS11?

@macrozone
Copy link
Collaborator

macrozone commented Mar 5, 2018

you can use this: https://github.com/HippoAR/react-native-arkit/blob/8f872ea40d89e1f4b205a96e12ec93edf0079345/ios/RCTARKit.m#L241

this does a runtime check

just change it to 11.0 or so

@michbil
Copy link
Author

michbil commented Mar 5, 2018

I tried


- (NSDictionary *)getSceneObjectsHitResult:(const CGPoint)tapPoint  {
    if (@available(iOS 11.0, *)) {
    NSDictionary *options = @{
                              SCNHitTestRootNodeKey: self.localOrigin,
                              SCNHitTestSortResultsKey: @(YES),
                              SCNHitTestOptionSearchMode: @(SCNHitTestSearchModeAll)
                              };
    NSArray<SCNHitTestResult *> *results = [_arView hitTest:tapPoint options:options];
    NSMutableArray * resultsMapped = [self mapHitResultsWithSceneResults:results];
    NSDictionary *result = getSceneObjectHitResult(resultsMapped, tapPoint);
    return result;
    } else {
        return nil;
    }
}

but no luck, its still crashes at starutp, because once compiled runtime is searching for this symbol.
This code is not executed in iOS10 in any way, that's why run time check doesn't help.
I think we need to replace @(SCNHitTestSearchModeAll) with some dynamic import statement, but i'm not so good at Objective-C to figure out it myself.

@macrozone
Copy link
Collaborator

it should work with this runtime check. Does xcode give you any warning, if you change the target to ios 10 or so?

@michbil
Copy link
Author

michbil commented Mar 19, 2018

@macrozone not sure about warnings, but this change solved issue:

  NSDictionary *options = @{
                              SCNHitTestRootNodeKey: self.localOrigin,
                              SCNHitTestSortResultsKey: @(YES),
                              @"SCNHitTestOptionSearchMode": @(SCNHitTestSearchModeAll)
                              };
    NSArray<SCNHitTestResult *> *results = [_arView hitTest:tapPoint options:options];
    NSMutableArray * resultsMapped = [self mapHitResultsWithSceneResults:results];
    NSDictionary *result = getSceneObjectHitResult(resultsMapped, tapPoint);
    return result;```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants