2017-02-01 95 views
2

我使用OneSignal SDK作爲反應本機。我嘗試禁用焦點時應用程序的內部警報。你有一個想法如何做到這一點?ios:禁用應用程序焦點時的警報通知(OneSignal)

這裏是我的代碼:

OneSignal.configure({ 
onIdsAvailable: function (device) { 
    console.log('UserId = ', device.userId); 
console.log('PushToken = ', device.pushToken); 
getUserId(device.userId); 
}, 
onNotificationReceived: function (notification) { 
OneSignal.checkPermissions((permissions) => { 
    console.log(permissions); 
}); 
OneSignal.inFocusDisplaying(0); 
}, 
onNotificationOpened: function(message, data, isActive) { 
console.log("MS TYPE", message); 
switch(message.notification.payload.additionalData.type) { 
case '1': 
     Actions.messenger({id:  message.notification.payload.additionalData.userID}); 
    break; 
case '2': 
     Actions.overview(); 
    break; 
    } 
    } 
}); 

回答

1

我想在你的代碼的問題出在哪裏放置OneSignal.inFocusDisplaying(0);

你需要把它放在componentWillMount

componentWillMount() { 
    OneSignal.addEventListener('received', this.onReceived.bind(this)) 
    OneSignal.addEventListener('opened', this.onOpened) 
    OneSignal.addEventListener('registered', this.onRegistered) 
    OneSignal.addEventListener('ids', this.onIds.bind(this)) 

    // Set inFocusDisplaying to prevent the default push notification alert when the is in focus 
    // Android ONLY 
    OneSignal.inFocusDisplaying(0) 
    } 
相關問題