-1
IOSデバイストークンをデータベースに送信して、phpとFirebaseを使用して通知に使用しようとしていますが、常にデバイストークンを空にしておきます!IOSデバイストークンがデータベースに空に送信されました
AppDelegateコード:
import UIKit
import SlideMenuControllerSwift
import GoogleMaps
import Firebase
import FirebaseCore
import UserNotifications
import Localize_Swift
var appDefaults = UserDefaults.standard;
var appDelegate = UIApplication.shared.delegate as! AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var notificationtoken:String = "";
func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken , type: FIRInstanceIDAPNSTokenType.prod)
self.notificationtoken = deviceToken.base64EncodedString();
sendDeveiceToken();
}
}
ログインコード
import UIKit
class LoginViewController: UIViewController ,UITextFieldDelegate{
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var loginBtn: UIButton!
var userlogin:userLogin?
override func viewDidLoad() {
super.viewDidLoad()
usernameTextField.delegate = self;
passwordTextField.delegate = self;
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func LoginAction(_ sender: UIButton) {
Shared.HUD.progressHUD(nil, message: nil);
if (usernameTextField.text != nil && passwordTextField.text != nil) {
//userLogin(user_name: String , password :String, device: String , Token: String)
GoldenTajProvider.request(.userLogin(user_name: usernameTextField.text!, password: passwordTextField.text!,Token: appDelegate.notificationtoken), completion: { (result) in
var success = true
var message = "Unable to fetch from GitHub"
Shared.HUD.hide(2)
switch result {
case let .success(moyaResponse):
do {
let repos = try moyaResponse.mapObject(userLogin)
if (repos.data != nil){
self.userlogin = repos;
if let user = self.userlogin{
userLogin.updateUserObject(user)
appDelegate.currentUserId = (user.data?.first?.iD!)!
appDelegate.currentUser = user;
}
UserDefaults.standard.setValue(accessToken, forKey: AppUserDefaults.AccessToken.rawValue);
UserDefaults.standard.set(true, forKey: AppUserDefaults.isLogedIn.rawValue);
appDelegate.presentMain();
}else {
let json = try moyaResponse.mapJSON() as! [String:Any]
message = json["data"] as! String
Shared.Alert("", message: message, confirmTitle: "OK", sender: self);
}
} catch {
success = false
}
case let .failure(error):
guard let error = error as? CustomStringConvertible else {
break
}
message = error.description
success = false
}
})
}
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}
}
これでも、デバイストークンをWebサービスに送信しようとすると、空になります。var notificationtoken:String = ""; self.notificationtoken = deviceToken.base64EncodedString(); –
let deviceTokenを使用してデバイストークンを取得する:String? = FIRInstanceID.instanceID()。token() –
appdelegate文字列のいずれかをログインコードに呼び出そうとすると、これも動作しません。それを空にし続ける! –