Hello I have an issue passing the device_token to my parameter swift 4 Xcode 9.2
ViewController
override func viewDidLoad() {
print("inside viewDidLoad ")
super.viewDidLoad()
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.viewController = self
}
func loadRequest(for deviceTokenString : String)
{
let deviceid = UIDevice.current.identifierForVendor!.uuidString
print("====== device id =======")
print(deviceid)
let testURL = URL(string: "http://www.test.com/user?device=ios&deviceid=" + deviceid + "&devicetoken=" + deviceTokenString
let testURLRequest = URLRequest(url: testURL!)
print("before load request")
print(testURL!)
RJWebview.loadRequest(testURLRequest)
}
AppDelegate -> didRegisterForRemoteNotificationsWithDeviceToken
viewController?.loadRequest(for: deviceTokenString!)
Send the data to my SQL database I'm using this method
let URL_USER_REGISTER = "http://api"
let parameters: Parameters=[
"first_name":textFieldFirstName.text!,
"last_name":textFieldLastName.text!,
"username":textFieldUsername.text!,
"email":textFieldEmail.text!,
"device_token":device_token,]
Alamofire.request(URL_USER_REGISTER, method: .post, parameters: parameters).responseJSON
{
response in
//printing response
print(response)
//getting the json value from the server
if let result = response.result.value {
//converting it as NSDictionary
let jsonData = result as! NSDictionary
//displaying the message in label
self.labelMessage.text = jsonData.value(forKey: "message") as! String?
}
}
And this is the Output
SUCCESS: {
code = 402;
errors = {
"device_token" = (
"validation.required"
);
};
message = error;
}
Should pass the device_token and send it from the parameter method but here I have 2 issues
1 - If i used "device_token":device_token, will give this error Use of unresolved identifier 'device_token'
should to get it from the func loadRequest
2 - If i used the "device_token":loadRequest, will return in the output this
And this is the Output
SUCCESS: {
code = 200;
"device_token" ="(FUNCTION)"
}
Please, any better way??