sometimes I getting
Server reported an error: javax.persistence.RollbackException: Error while committing the transaction
and sometimes the registration is fine.
tried to google the error with no success
sometimes I getting
Server reported an error: javax.persistence.RollbackException: Error while committing the transaction
and sometimes the registration is fine.
tried to google the error with no success
I also check if I getting token from APNS, I getting a token.
but when I register to channel, I getting an error.
I do a Backendless.UserService.Login and only then register to channel.
after deeper search, I have learned that it’s on server side rather then the application.
if I close the application and try again, it can register to channel, but if I close and open again, it can throw the error
javax.persistence.RollbackException: Error while committing the transaction
after checking that I get correct token from APN I make pushToken as object that I can take from AppDelegate.swift
I sometimes getting it, sometimes I don’t
I using device registration in ViewController.swift rather than AppDelegate.swift
code:
method to call for register the channel in English:
fileprivate func registerNewCity(_ myLocation:CLLocation)
{
if #available(iOS 11.0, *) {
CLGeocoder().reverseGeocodeLocation(myLocation, preferredLocale: Locale(identifier: "en"), completionHandler: completionHandler)
} else {
UserDefaults.standard.set(["en"], forKey: "AppleLanguages")
CLGeocoder().reverseGeocodeLocation(myLocation) { placemarks, error in
// Remove the language override
UserDefaults.standard.removeObject(forKey: "AppleLanguages")
self.completionHandler(placemarks, error)
}
}
}
then I use the method for registration:
fileprivate func completionHandler(_ placemarks: [CLPlacemark]?, _ error: Error?)
{
//register device
let backendless = Backendless.sharedInstance()
if let place = placemarks?.first {
backendless?.messaging.unregisterDevice()
// print(place.locality)
var chan:[String] =
//now take out the spaces
var tempCity:[String] = place.locality!.components(separatedBy: " “)
//self.txtCity.text = place.locality!
var myCity=”"
print (“tempCity:(tempCity)”)
for counter in 0…<tempCity.count
{
myCity+=tempCity[counter]
}
myCity = myCity.lowercased()
chan.append(myCity)
if isWorker{
chan.append(“(myCity)_shift”)
}
chan.append(“repo”)
chan.append(“dev”)
print (chan)
//checking something
if isWorker && workerCity == myCity {chan.append(myCity+"_shift")}
//chan.append(self.txtCity.text!+"_shift")
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
guard let pushToken = appDelegate.pushToken else {
print("can not get device token string")
return
}
backendless?.messaging?.registerDevice(pushToken, channels: chan, response: { (registeredDeviceId:String?) in
print("Device registered in Backendless")
}, error: { (err:Fault?) in
print (print("Server reported an error: \(err!.message!)"))
})
}
}
Hi Zeev,
Unfortunately 99% of the code is irrelevant here as it deals strictly with the logic of your app and not the Backendless API. Since you mention that the error occurs “sometimes” it must be something related to timing of the calls.
What is the reason that the registration is done in ViewController and not the AppDelegate class?
Regards,
Mark
I made upadate to the pod files, problems seems to be resolved, I will look for the problem if it return