小编A. *_*ali的帖子

异步函数没有在android上返回

我遇到一个问题,在运行Android时没有返回异步函数,而在iOS上运行时它会正常返回.

这是功能:

_getLocationAsync = async () => {
    let {status} = await Permissions.askAsync(Permissions.LOCATION);
    if (status !== 'granted') {
        this.setState({
            errorMessage: 'Permission to access location was denied',
        });
    }

    let location = await Location.getCurrentPositionAsync({});

    this.setState({location});
    return location;
};
Run Code Online (Sandbox Code Playgroud)

我在另一个函数中使用它:

async fetchMarkers(settings ){
    console.log("fetchMarkers");
    // console.log(settings);
    this.setState({listLoading: true});


    let location = await this._getLocationAsync();
    console.log("location is ", location);
    ....
    ....
}
Run Code Online (Sandbox Code Playgroud)

这行不是在android中返回,但它以ios返回.在android中我尝试在_getLocationAsync中返回之前记录location的值,它记录了一个已定义且正确的对象,我想知道为什么它没有返回它然后:

let location = await Location.getCurrentPositionAsync({});
Run Code Online (Sandbox Code Playgroud)

我正在使用React Native 0.53

javascript async-await react-native react-native-android

10
推荐指数
1
解决办法
759
查看次数

在c中匹配一个确切的单词

我可以使用strstr函数来匹配确切的单词吗?例如,假设我有单词hello和输入字符串line:

如果

char* line = "hellodarkness my old friend";
Run Code Online (Sandbox Code Playgroud)

我用

result = strstr(line, "hello");
Run Code Online (Sandbox Code Playgroud)

result将匹配(不是NULL),但我想只匹配确切的单词"hello"(以便"hellodarkness"不匹配),结果将为NULL.是否可以使用strstr或者我必须fscan逐字逐句扫描并检查匹配?

c strstr

2
推荐指数
1
解决办法
2257
查看次数