2017-06-08 23 views

cevap

13

OneSignal'ın OSSubscriptionObserver gibi gözlemcileri kullanmanız gerekir. Daha iyi bir açıklama için

// 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)") 
     } 
    } 
} 

, burada Sen standardUserDefaults içinde bulabilirsiniz addSubscriptionObserver

+0

sayesinde:

Bu kodu kullanarak sona erdi! – aznelite89

+0

Rica ederim :) – GabrielaBezerra

+0

Bence böyle bir şey için zor. OneSignal, oyuncu kimliğini günlüklere yazdırmalıdır. –

-2

için belgelerdir. Aşağıdakileri kullanarak alabilirsiniz. İlk uygulama lansmanında ayarlandığına inanıyorum, ancak ilk kez application:didFinishLaunchingWithOptions: çağrılmamış olabilir.

UserDefaults.standard.string(forKey: "GT_PLAYER_ID") 

Sen Sözlük temsil bakarak kullanıcı varsayılan saklanır başka ne görebilirsiniz: Benim kod içinde bir yerde Oyuncu Kimliği olsun (Ya KullanıcıNo) gerekiyor UserDefaults.standard.dictionaryRepresentation()

0

ve ben istemiyorum herhangi bir yere kaydetmek için. Bu mükemmel çalıştı,

let userId = OneSignal.getPermissionSubscriptionState().subscriptionStatus.userId 
İlgili konular