Swift :- How to do the customize report for Crashlytics in Swift
I didn't know Crashlytics has the beta version for the crash report with the correct syntax. I found it and tested it out it is working now! I used the debug example codes from Firebase to tested the report. Please check out the codes and the screenshots.
FirebaseCrashlytics Customize Crash Report
override func viewDidLoad() {
super.viewDidLoad()
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
if isFromChatBot == true {
showIntakeOptions()
}
let button = UIButton(type: .roundedRect)
button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
button.setTitle("Crash", for: [])
button.addTarget(self, action: #selector(self.crashButtonTapped(_:)), for: .touchUpInside)
view.addSubview(button)
Crashlytics.crashlytics().setCustomValue("\(isFromChatBot)", forKey: "viewdeloadTest")
Crashlytics.crashlytics().log("viewdeloadTestForCrash")
}
@IBAction func crashButtonTapped(_ sender: AnyObject) {
Crashlytics.crashlytics().setCustomValue("test", forKey: "test1")
Crashlytics.crashlytics().log("crashbuttonTapped")
//Analytics.logEvent("Setup screen", parameters: nil)
fatalError()
}
Understanding Firebase Crashlytics report for iOS app
All UI stuff should be performed on main thread, that is what your crash report shows (crash due to main thread.)
So your last line should be :
DispatchQueue.main.async {
self.contactNumberText.text = altenativeMobile
}
Update this line, your crash will fixed.
How to report a non-fatal exception with Firebase crash on iOS?
According to the documentation, you can only report fatal errors on iOS at this time.
Firebase Swift 3 Database crashes on setValue withCompletionBlock
tl;dr: Firebase provides a setValue(_ value: Any?, andPriority priority: Any?)
which is incorrectly matched when using a trailing closure with setValue(_ value: Any?, withCompletionBlock: (Error?, FIRDatabaseReference) -> Void)
.
Solution: When using an API that has many varieties, avoid using trailing closures. In this case, prefer setValue(myValue, withCompletionBlock: { (error, dbref) in /* ... */ })
; do not use setValue(myValue) { (error, dbref) in /* ... */ }
.
Explanation
This appears to be a Swift bug. As in other languages, such as Java, Swift generally chooses the most specific overload. E.g.,
class Alpha {}
class Beta : Alpha {}
class Charlie {
func charlie(a: Alpha) {
print("\(#function)Alpha")
}
func charlie(a: Beta) {
print("\(#function)Beta")
}
}
Charlie().charlie(a: Alpha()) // outputs: charlie(a:)Alpha
Charlie().charlie(a: Beta() as Alpha) // outputs: charlie(a:)Alpha
Charlie().charlie(a: Beta()) // outputs: charlie(a:)Beta
However, when overloaded functions match a trailing closure, Swift (at least, sometimes) selects the more general type. E.g.,
class Foo {
func foo(completion: () -> Void) {
print(#function)
}
func foo(any: Any?) {
print(#function)
}
}
func bar() {}
Foo().foo(completion: bar) // outputs: foo(completion:)
Foo().foo(any: bar) // outputs: foo(any:)
Foo().foo() { () in } // outputs: foo(any:)
// ^---- Here lies the problem
// Foo().foo(bar) will not compile; can't choose between overrides.
Any?
is a more general type than () -> Void
-- i.e., "anything, even null" is more broad than "a function receiving 0 parameters and returning something of type Void
". However, the trailing closure matches Any?
; this is the opposite of what you would expect from a language that matches the most specific type.
Customizing the Remove Button and Logging the Number of Removals
I would like that instead of the button saying "Remove" it says report.
This can be easily done by - yourButton.setTitle("Report", for: .normal)
or
yourButton.titleLabel?.text = "Report"
Coming to the next part -
Whenever someone reports, you need to call API or whatever way you are using to update the stored value of report count, then reflect this in your app by getting the newly increased value in response.
You can use Timer
to check the value of report counter in your desired time interval, and if the value exceeds, remove the post.
Edit - As there is no use of buttons
You can change the title of that red box by these delegate methods
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
tableView.setEditing(true, animated: true)
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
{
let more = UITableViewRowAction(style: .default, title: "Report")
{ action, index in
print("Report button tapped")
}
more.backgroundColor = UIColor.blue
return [more]
}
Related Topics
How to Loop All Firebase Children at Once in the Same Loop
Autoscrolling Infinite Effect in .Linear Type of Icarousel in Swift
Can Openssl Be Bundled for Wget Wrapper App to Reference in Xcode Project
Why Does Classa Adopting Protocolb Not Satisfy the Protocolb Requirement
Nsurl Fail Able Initialiser Initwithstring: Does Not Return Nil on Empty String in Swift
Swift Why Isn't My Date Object That's (Equatable) Equal After Converting It to a String and Back
Change Mkmarkerannotationview Size
Swift: Nil Error When Using Self.Moc.Save() to Save in Core Data
Getch() Equivalent in Swift: Read a Single Character from Stdin Without a Newline
Using Tvposterimage in Tvuikit for Tvos 12
Swiftui: Unexpected Animation When Using a Non @State Var
Realitykit - How to Add Motion to a Loaded Modelentity from Usdz File
Use Huge Numbers in Apple Swift
Swiftui How to Programatically Adjust Spacing Between Images and Text
Swift Catch Enum Case with Binding
Cannot Invoke "+=" with an Argument List of Type (Int, @Value Int)