Skip to main content

How To: User Reporting

Users can report callers as Spam, Fraud, Not Spam, and other categories as well as optionally including a comment.

First retrieve a list of valid report categories using Hiya.getReportCategories(@escaping completion: (categories, error)), then send a report using Hiya.postPhoneReport(profile, category, comment, completion: @escaping (status, error))

If a PhoneProfile for the number to report is not available, one can be generated using the Hiya.lookup(number:completion:) method.

/// List of report categories retrieved from the server.
var reportCategories: [ReportCategory]

/// Profile of number being reported.
var phoneToReport: PhoneProfile

/// ReportCategory to assign to the number.
var selectedCategory: ReportCategory

/// Text comment to include with report.
var reportComment: String

// First get a list of report categories
Hiya.getReportCategories() { categories, error in
if let error {
print("Error getting report categories: \(error.localizedDescription)")
return
}
if let categories {
self.reportCategories = categories
}
}

// Once the list of report categories has been retrieved, a phone report can be sent.
Hiya.postPhoneReport(profile: self.phoneToReport, category: self.selectedCategory, comment: self.reportComment) { status, error in
if let error {
print("Error sending phone report: \(error.localizedDescription)")
}
}