如何在iOS中实现一个基本的投票机制来防止重复投票?
我正在我的 iOS 应用程序中展示内容,我希望用户能够投票。我不想实现复杂的“注册用户名”功能,而是希望用户能够投票。
在 Web 开发领域,我可以通过使用客户端的 IP 地址来防止重复投票。
如何制作一个简单的投票系统,让用户只能对某个帖子投票一次而不用担心重复投票?
I am showcasing content in my iOS app and I would like users to be able to vote. Instead of implementing a complicated "register a username" functionality, I just want a user to be able to upvote.
In the World of web development I could prevent duplicate votes by using the IP address of the client.
How can I make a simple voting system that allows a user to be only able to vote up a post once and not worry about duplicates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过设备 ID 来完成:
您可以实施检查,以便每个设备 ID 只能投票一次。
但是,请记住,设备 ID 特定于每个设备,因此这意味着如果单个用户拥有多个设备(ipad、iphone、ipod touch 等),他们可以多次投票(每个设备一次)。
You could do it by device id:
You could implement a check so that each device id can only upvote once.
However, keep in mind that the device id is specific to each device, so that means that if a single user had multiple devices (ipad, iphone, ipod touch etc.) they could vote multiple times (once per each device).
不要像 Apple 所说的那样使用
uniqueIdentifier
:相反,我建议从
uniqueIdentifier
更改为 这个开源库(实际上是 2 个简单的类别)。它利用设备的 MAC 地址和应用程序包标识符在您的应用程序中生成可用作 UDID 替代品的唯一 ID。请记住,与 UDID 不同,每个应用程序的该数字都不同。
您只需导入包含的
NSString
和UIDevice
类别并调用:您可以在 Github 上找到它:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
这是代码(只是.m 文件 -检查 github 项目的标头):
UIDevice+IdentifierAddition.m
NSString+MD5Addition.m:
Dont use
uniqueIdentifier
as Apple has stated:Instead, I would suggest changing over from
uniqueIdentifier
to this open source library (2 simple categories really). It utilizes the device’s MAC Address along with the App Bundle Identifier to generate a unique ID in your applications that can be used as a UDID replacement.Keep in mind that unlike the UDID this number will be different for every app.
You simply need to import the included
NSString
andUIDevice
categories and call:You can find it on Github here:
https://github.com/gekitz/UIDevice-with-UniqueIdentifier-for-iOS-5
Heres the code (just the .m files - check the github project for the headers):
UIDevice+IdentifierAddition.m
NSString+MD5Addition.m: