आपको OSSubscriptionObserver जैसे OneSignal के पर्यवेक्षकों का उपयोग करने की आवश्यकता है।
// Add OSSubscriptionObserver after UIApplicationDelegate
class AppDelegate: UIResponder, UIApplicationDelegate, OSSubscriptionObserver {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Add your AppDelegate as an subscription observer
OneSignal.add(self as OSSubscriptionObserver)
}
// After you add the observer on didFinishLaunching, this method will be called when the notification subscription property changes.
func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) {
if !stateChanges.from.subscribed && stateChanges.to.subscribed {
print("Subscribed for OneSignal push notifications!")
}
print("SubscriptionStateChange: \n\(stateChanges)")
//The player id is inside stateChanges. But be careful, this value can be nil if the user has not granted you permission to send notifications.
if let playerId = stateChanges.to.userId {
print("Current playerId \(playerId)")
}
}
}
एक बेहतर विवरण के लिए, यहाँ के लिए addSubscriptionObserver
धन्यवाद, यह एक आकर्षण की तरह काम किया! – aznelite89
आपका स्वागत है :) – GabrielaBezerra
मुझे लगता है कि ऐसी चीज के लिए मुश्किल है। OneSignal लॉग में प्लेयर आईडी मुद्रित करना चाहिए। –