iOS应用程序从本地搜索中获得限制

前端之家收集整理的这篇文章主要介绍了iOS应用程序从本地搜索中获得限制前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在一个搜索地址的应用程序中实现自动完成(每个新添加的字符一个搜索),并且我继续收到MKErrorDomain错误3,这是MKErrorLoadingThrottled.这个错误,根据 Apple dev,发生时

The data was not loaded because data throttling is in effect. This
error can occur if an app makes frequent requests for data over a
short period of time.

我确切地知道正在进行多少请求,一个用于搜索查询中的每个新字符(就像您希望自动完成工作一样).当然,我是一个快速的老板,但只要10或15个请求似乎是荒谬的,可以达到极限.看看以下两个来源引用,我不明白为什么我不断被扼制.

根据Apple dev

There are no request limits per app or developer ID,so well-written
apps that operate correctly should experience no problems. However,
throttling may occur in a poorly written app that creates an extremely
large number of requests.

和詹姆斯·霍华德said at a WWDC:

And the other thing I want to talk about is the Usage Limits on this
API.
So,I’m happy to announce that there’s no application or developer
identifier wide usage limits.
So,if you have a app that has a lot of users and you want to do a lot
of requests,that’s fine.

It’ll work.

And the throttling that we do have is really just a first line of
defense against buggy apps.
So,if you put directions requests or local search requests in an
infinite loop,you’ve got a bug,eventually you’re going to get
throttled.

But if you do something reasonable,you say oh,I’m going to just do
directions in response to user input and you know you can do a few of
those because we showed them that example.

Like we did two directions request in response to one user input,
that’s fine.
But,you know if you’re doing 10,000 every time the user taps on the
screen,then you’re going to get throttled.
But,just keep it reasonable and you’ll be fine.

任何想法为什么这是发生?

解决方法

自动完成需要一个特殊的API. MapKit不提供这样的界面.只需开启数十个对正常搜索API的请求就会产生巨大的负担.

你基本上有两个选择:

>使用Google商家信息.他们有一个专门的Places Autocompletion API.甚至有一个完整的图书馆为iOS在GitHub.>减少请求的数量,例如只有当用户已经暂停输入300ms并且只有没有先前的请求未完成时才发送请求.但是,这并不能保证苹果不会限制您的请求.

猜你在找的iOS相关文章