1

Google 프로젝트에 현재 노드 jS 백엔드가 있으며 iOS 용 푸시 알림을 구현하려고합니다. Google은 일부 조사를 수행하여 특정 기기에 푸시 알림을 보내기 위해 APN이 Google에 제공 한 토큰을 저장해야한다는 것을 알아 냈습니다. 다른 사람이이를 확인하거나 알림을 보내는 더 좋은 방법이 있습니까?푸시 알림 용 토큰 저장

둘째, 장치가 소프트웨어 업데이트를 통해 토큰을 변경하면 장치가 자주 변경되므로 DB에서 토큰을 업데이트 할 수 있어야한다는 것을 발견했습니다. 이것은 또한 매우 중요합니다. 토큰이 변경 될 수있는 다른 시간이 있습니까?

마지막으로 푸시 알림을 보내기 위해 노드에 좋은 라이브러리가 있습니까?

미리 감사드립니다.

답변

2

알림을 전달하려면 해당 주소 인 서버에 알림 accessToken을 보내야합니다. accesstoken의 변형에 대해 걱정할 필요가 없습니다. 매번 로그인 할 때마다 보내야하기 때문에 새로운 업데이트 된 accesstoken도 서버에 추가됩니다. Appdelegate에 원격 알림을 등록하고 나중에 저장된 토큰을 보내야합니다. 로그인 API에서 nsuserdefault에서 서버로.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
    // Override point for customization after application launch. 


    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) 
     UIApplication.sharedApplication().registerUserNotificationSettings(settings) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
    return true 
} 

//Called if successfully registered for APNS. 
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
    // let deviceTokenString = NSString(format: "%@", deviceToken) as String 

    var tokenStr = deviceToken.description 
    tokenStr = tokenStr.stringByReplacingOccurrencesOfString("<", withString: "", options: [], range: nil) 
    tokenStr = tokenStr.stringByReplacingOccurrencesOfString(">", withString: "", options: [], range: nil) 
    tokenStr = tokenStr.stringByReplacingOccurrencesOfString(" ", withString: "", options: [], range: nil) 
    print(deviceToken.description) 
    print(tokenStr) 
    //save the token in NSUserDefaults 
    NSUserDefaults.standardUserDefaults().setObject(deviceTokenString, forKey: "deviceToken") 


} 

//Called if unable to register for APNS. 
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) { 

    print(error) 

} 

Reference Apple's Documentation

장치 토큰은 특정 장치에 응용 프로그램 에 푸시 알림을 전송하는 키입니다. 기기 토큰이 변경 될 수 있으므로 앱을 시작할 때마다 을 다시 등록해야하고 수신 된 토큰을 서버에 다시 전달하십시오 ( ). 기기 토큰을 업데이트하지 못하면 원격 알림이 사용자 기기로 전송되지 않을 수 있습니다. 장치 토큰은 사용자가 백업 데이터를 새로운 장치 또는 컴퓨터로 복원하거나 운영 체제를 다시 설치하면 항상 변경됩니다. 데이터를 새 기기 또는 컴퓨터로 이전 할 때 사용자는 번 앱을 실행해야 원격 알림을 해당 기기로 전송할 수 있습니다.

+0

이 답변을 주셔서 감사합니다.하지만 두 사람 사이에 알림을 보내고 싶다면 여전히 데이터베이스에 저장합니까? 고마워요 –

+0

예, 사용자가 9 명 이후로 앱을 재설치하거나 휴대 전화를 복원 할 때 액세스 권한이 변경 되어도 사람이 여러 명일 수있는 경우에도 두 사람 사이의 데이터베이스가 변경 되더라도 데이터베이스를 유지 관리해야합니다. 따라서 데이터베이스를 반드시 유지 관리해야합니다. –