React Native PushNotificationIOS
๋ชจ๋์๋ ์ฑ์ ์ด๊ธฐ ์ํด ํญํ ์๋ฆผ์ ๊ฐ์ ธ์ฌ ์ ์๋ getInitialNotification()
๋ฉ์๋๊ฐ ์์ต๋๋ค(์๋ ๊ฒฝ์ฐ). ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ ์ฌํ ๊ธฐ๋ฅ์ด ์์ต๋๊น?
์ฑ์ด ๋ซํ ์ํ์์ ๋ด ์ฅ์น์ ํ
์คํธ ์๋ฆผ์ ๋ณด๋์ ๋ ์ฝ์์ด ์ด๋ ธ์ ๋ Device info:
๋ก๊ทธ๋ฅผ ์์ ํ์ง๋ง ์๋ฆผ ์์ ์ ๋ํ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ก๊ทธ๋ ๋ณด์ง ๋ชปํ์ต๋๋ค.
ํธ์ง 3:
์ด๋ค ์ด์ ๋ก ์ด๊ธฐ ์๋ฆผ์ ๋ํ onOpened
์ด๋ฒคํธ๋ฅผ ๋ ์ด์ ๋ณผ ์ ์์ง๋ง ์ฝ๋์์ ๋ณ๊ฒฝ๋ ์ฌํญ์ ์์ต๋๋ค.
ํธ์ง 2:
๋ฆฌ์ค๋ ์ฃผ์๋ฅผ ์ด๋ํ์ฌ onOpened
์ด๋ฒคํธ์ ๋ํ ๋ก๊ทธ๋ฅผ ๋ณผ ์ ์์์ง๋ง ์๋ ๋ฆฌ์ค๋๋ผ๋ ๊ฒ์ ๋ด ์ฑ์ด ์๋ฆผ๊ณผ ํจ๊ป ์ด๋ ธ๋์ง ์ฌ๋ถ๋ฅผ ์์ํ ๋ ์ ๊ทน์ ์ผ๋ก ํ์ธํ ์ ์์์ ์๋ฏธํฉ๋๋ค. , ํด๋น ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋์ง ํ์ธํ๋ ค๋ฉด ์์์ ์๊ฐ ๋์ ๊ธฐ๋ค๋ ค์ผ ํฉ๋๊น? ํธ์ ์๋ฆผ์ผ๋ก ์ฑ์ด ์ด๋ ธ๋์ง ๋ฅ๋์ ์ผ๋ก ํ์ธํ ์ ์๋ ๋ฐฉ๋ฒ์ ์๋์?
ํธ์งํ๋ค:
OneSignal.configure()
๋ฐ onNotificationOpened
๋ฅผ ์ฌ์ฉํ์ฌ ์ฐธ์กฐํ๋ ๊ธฐ์ฌ ๋ฅผ ์ฐพ์์ง๋ง ์์ค ์ฝ๋๋ฅผ ๋ณด๋ฉด OneSignal.configure()
๊ฐ ๋ ์ด์ ๋งค๊ฐ๋ณ์๋ฅผ ํ์ฉํ์ง ์๋ ๊ฒ์ผ๋ก ๋ณด์
๋๋ค.
์ ์๊ฒ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๊ณ ๋ค๋ฅธ ๋ง์ ๋ถ๋ค๋ ์ด ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ด๊ฐ ์ฐพ์ ์ผ๋ถ ๊ด๋ จ/์ค๋ณต ๋ฌธ์ ์๋ https://github.com/geektimecoil/react-native-onesignal/issues/206 , https://github.com/geektimecoil/react-native-onesignal/issues/195 , https://github.com/geektimecoil/react-native-onesignal/issues/191 , https://github.com/geektimecoil/react-native-onesignal/issues/336 , https://github.com/geektimecoil/ react-native-onesignal/issues/334 , https://github.com/geektimecoil/react-native-onesignal/issues/264 , https://github.com/geektimecoil/react-native-onesignal/issues/279.
์ด ๋ฌธ์ ๋ ๋ชจ๋ ํธ์ ์๋ฆผ์ ๋๋ฌ ์ฑ์ ์ด ๋ opened
์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ํธ์ถ๋์ง ์๊ณ ์ฑ์ด ์คํ ๋์ง ์๋ ์ด ๋ฌธ์ ์ ๋ํ ๊ฒ ๊ฐ์ต๋๋ค. ํด๋น ๋ฌธ์ ์ ๋ด๊ฐ ์ํํ ํ
์คํธ์์ ์ฝ์ ๋ด์ฉ์ ๋ฐ๋ฅด๋ฉด ์ด ๋ฌธ์ ์ ์์ธ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก์ด ์ด๋ค ์์ผ๋ก๋ ์ง์ฐ๋๋ ๊ฒ ๊ฐ์ต๋๋ค(์: OneSignal.addEventListener('opened', this.onOpened);
๋ ์ฑ ์์ฒด๊ฐ ๋ก๋๋จ). ์ด๊ฒ์ React ๊ตฌ์ฑ ์์ ๋ด์ ์ด ์ฝ๋๊ฐ ์๊ธฐ ๋๋ฌธ์ผ ์ ์์ต๋๋ค(์: constructor
๋๋ componentWillMount
๋๋ componentDidMount
ํจ์) ๋๋ ๊ตฌ์ฑ/์ฌ์ํ ํ๊น์ง ํธ์ถ๋์ง ์๊ธฐ ๋๋ฌธ์ผ ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ์ง์ฐ์ผ๋ก ์ธํด ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋๊ธฐ ์ ์ react-native-onesignal์ ์ํด ์ด๋ฒคํธ ์์ฒด(์๋ฆผ์ด ์ด๋ ธ์)๊ฐ ๋ฐ์ํ๊ณ ์ด ์์ ์์ ์ด๋ฒคํธ๋ฅผ ๋์ณค๊ณ ๋์๋์ง ์ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ์ฐธ๊ณ ๋ก ์ด ๋์ผํ ๋ฌธ์ ๋ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฆฌ์ค๋(์: ids
์ด๋ฒคํธ ๋ฆฌ์ค๋)์ ์ํฅ์ ๋ฏธ์นฉ๋๋ค.
๊ฐ๋ฅํ ํ ๋นจ๋ฆฌ ๋ฐ์ํ๋๋ก ์ด ์ฝ๋๋ฅผ ์ด๋ํ๋ฉด ์ด๋ฒคํธ๊ฐ ์์๋๊ธฐ ์ ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋์ด ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๊ฐ ํธ์ถ๋๋ ๊ฒ์ผ๋ก ๋ณด์
๋๋ค. ์๋ฅผ ๋ค์ด ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก ์ฝ๋๋ฅผ index.ios.js
ํ์ผ๋ก ์ด๋ํ๊ฑฐ๋ index.ios.js
ํ์ผ์ด ๋จ์ํ ๊ฐ์ ธ์ค๊ธฐ๋ง ํ๋ ๊ฒฝ์ฐ App.js
ํ์ผ์ ์์ ๋ถ๋ถ์ผ๋ก ์ด๋ํด์ผ ํฉ๋๋ค. App
๊ตฌ์ฑ ์์๋ฅผ ๋ง๋ค๊ณ ๋ฑ๋กํฉ๋๋ค( AppRegistry.registerComponent
๋ฅผ ํตํด).
์ด ์ค์ ์ด ์๋ฃ๋๋ฉด ์ด์ ์๋ฆผ์ด ์ด๋ฆฐ ์ด๋ฒคํธ๋ฅผ ์บก์ฒํ ์ ์์ผ๋ฉฐ ์ด๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์ฑ ์ค์ ๋ฐฉ๋ฒ(์: ์ฌ์ฉ ์ค์ธ์ง ์ฌ๋ถ์ ๋ฐ๋ผ ๋ค๋ฆ ๋๋ค. Redux, ๋๋ redux-persist๋ฅผ ์ฌ์ฉ ์ค์ธ์ง ์ฌ๋ถ ๋ฑ).
๋ด ํ์ฌ ์๋ฃจ์
์ ๋ด App.js
ํ์ผ ์์ฒด์ ์ต์์ ์์ค์์ ์ ์๋ ๋ณ์์ ์๋ฆผ์ ์ ์ฅํ๋ ๊ฒ์
๋๋ค(๋ด App
๊ตฌ์ฑ ์์๋ฅผ ์ ์ธํ๊ธฐ ์ ์๋). ๊ทธ๋ฐ ๋ค์ ์ด๊ธฐํ๋ฅผ ์๋ฃํ๋ฉด ๋ด Redux ์คํ ์ด(redux-persist์ ์ํ ๋ด ์คํ ์ด์ ์ฌ์ํ ๋๊ธฐ ํฌํจ), ํ์ด๋ก๋๋ก ์๋ฆผ์ ์ฌ์ฉํ์ฌ ์์
์ ๋ฐ์กํ๊ณ (์๋ฆผ์ด ์ด๋ฆฐ ๊ฒฝ์ฐ) ์ต์์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ ์ ๊ฑฐํ๊ณ ์ ์ด๋ฒคํธ๋ฅผ ์ถ๊ฐํฉ๋๋ค. ๋ด App
๊ตฌ์ฑ ์์ ์์ฒด์ ๋ฆฌ์ค๋(์ด ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ ์๋ฆผ, ์ฅ์น ID ๋ฑ์ ์ก์
ํ์ด๋ก๋๋ก ์ฌ์ฉํ์ฌ Redux ์ ์ฅ์์ ์ก์
์ ์ ๋ฌํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค).
์ด ์๋ฃจ์ ์ ๋ถ๋ช ํ ๋งค์ฐ ํดํคํ๊ณ ์ด๊ฒ์ด ์์๋๋ก ์๋ํ์ง ์๋ ์ผ๋ถ ๊ทน๋จ์ ์ธ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ react-native-onesignal์์ ์ ์ ํ ์๋ฃจ์ ์ด ๊ตฌํ๋ ๋๊น์ง ์ด๊ฒ์ ์ ์ ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๊ธฐ ์ ์ ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ฅผ ์ค์ ํ ๋๊น์ง ๊ธฐ๋ค๋ฆฌ๋๋ก react-native-onesignal์ด ์
๋ฐ์ดํธ๋์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ํ ๊ฐ์ง ๊ฐ๋ฅํ ์๋ฃจ์
์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ฉด(์: opened
์ด๋ฒคํธ) ์ด๋ฒคํธ๊ฐ ๋๊ธฐ์ด์ ๋ค์ด๊ฐ๊ณ react-native-onesignal์ด ํ์ฌ ๋ฑ๋ก๋ ํด๋น ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ์๋์ง ํ์ธํ๋ ๊ฒ์
๋๋ค. ์๋ ๊ฒฝ์ฐ ๋๊ธฐ์ด์ ์ด๋ฒคํธ๋ฅผ ๋จ๊ฒจ๋ก๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋์๋ง์ ์ด ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ์์ ํ ์ด๋ฒคํธ๊ฐ ์์๋๊ณ ํ์์ ์ ๊ฑฐ๋ฉ๋๋ค. ๊ทธ๋ ๊ฒ ํ๋ฉด ์ฑ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ธ์ ๋ ์ง ์ถ๊ฐํ ์ ์์ต๋๋ค(์: Redux ์คํ ์ด๊ฐ ๊ตฌ์ฑ๋๊ณ ์ฌ์ํ๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฐ ํ, ์ฑ ์์ฒด๊ฐ ๋ก๋๋ ํ 1-2์ด๊ฐ ๋ ์ ์์). ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋๋ฉด ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๊ฐ ํธ์ถ๋๊ณ ๋ฐ์ํ ์ด๋ฒคํธ(์: ์๋ฆผ์ด ์ด๋ฆฐ ์ด๋ฒคํธ)๋ฅผ ์์ ํฉ๋๋ค.
์ฌ์ฉ์๊ฐ ํธ์ ์๋ฆผ์ ํญํ๊ธฐ ๋๋ฌธ์ ์ฑ์ด ์ด๋ ธ์์ ์ ์ด๋ ๊ฐ์งํ๊ธฐ ์ํ ๋ ๋ค๋ฅธ ๊ฐ๋ฅํ ์๋ฃจ์
์ ์ ์ํ ๋๋ก getInitialNotification()
from PushNotificationIOS
์ ์ ์ฌํ ์์
์ ์ํํ๋ ๊ฒ์
๋๋ค. ์ธ์ ๋ ์ง ํด๋น ๊ธฐ๋ฅ์ ํธ์ถํ๋ฉด ์ฌ์ฉ์๊ฐ ์ฑ์ ์ด๊ธฐ ์ํด ํญํ ํธ์ ์๋ฆผ์ ๋ฐํํฉ๋๋ค(๋๋ ์ด๊ฒ์ด ๋ฐ์ํ์ง ์์ ๊ฒฝ์ฐ null
). ๊ทธ๋ฌ๋ ์ด๊ฒ์ด react-native-onesignal์์ ๊ตฌํ๋๋๋ผ๋ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฆฌ์ค๋(์: ids
์ด๋ฒคํธ ๋ฆฌ์ค๋)์ ์ํฅ์ ๋ฏธ์น๋ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์๋ฌด ๊ฒ๋ ํ์ง ์์ต๋๋ค.
๋ฐ๋ผ์ ํด๋น ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋๊ธฐ ์ ์ ๋ฐ์ํ๋ ์ด๋ฒคํธ์ ํต์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ฌ ์ฑ์์ ์ด๋ฒคํธ๋ฅผ ๋์น๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์๋ฃจ์ ์ด ์ ๋ง๋ก ํ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
@jordanmkoncz๋ , ์๋ ํ์ธ์, ์์ ์ ๋ณด๋ธ ํ์ผ์ ์ฝ๋๋ฅผ ๊ณต์ ํ ์ ์์ต๋๊น? ๋๋ ๋น์ ๊ณผ ๊ฐ์ ๋ฐ์ ๋ค์ดํฐ๋ธ ์ค์ ์ ๊ฐ์ง๊ณ ์์ต๋๋ค (redux-persist ๋ฑ).
@ccoeder ํ์คํ, ์ฌ๊ธฐ ๋ด ํ์ฌ App.js
ํ์ผ์ด ์์ต๋๋ค.
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import OneSignal from 'react-native-onesignal';
import isNil from 'lodash/isNil';
import configureStore from '../redux/configureStore';
import {
pushNotificationIdsReceived,
pushNotificationOpened,
pushNotificationReceived,
pushNotificationRegistered,
} from '../redux/actionCreators';
import AppNavigator from './AppNavigator';
import Blank from './Blank';
let openedPushNotificationResult = null;
let receivedPushNotification = null;
let receivedNotificationUserInfo = null;
let receivedIds = null;
const onOpened = openResult => {
openedPushNotificationResult = openResult;
};
const onReceived = notification => {
receivedPushNotification = notification;
};
const onRegistered = notificationUserInfo => {
receivedNotificationUserInfo = notificationUserInfo;
};
const onIds = ids => {
receivedIds = ids;
};
OneSignal.addEventListener('opened', onOpened);
OneSignal.addEventListener('received', onReceived);
OneSignal.addEventListener('registered', onRegistered);
OneSignal.addEventListener('ids', onIds);
class App extends Component {
constructor() {
super();
this.state = {
isStoreInitialised: false,
};
this.store = null;
this.onOpened = this.onOpened.bind(this);
this.onReceived = this.onReceived.bind(this);
this.onRegistered = this.onRegistered.bind(this);
this.onIds = this.onIds.bind(this);
}
componentDidMount() {
this.store = configureStore(store => {
if (!isNil(openedPushNotificationResult)) {
store.dispatch(pushNotificationOpened(openedPushNotificationResult));
}
if (!isNil(receivedPushNotification)) {
store.dispatch(pushNotificationReceived(receivedPushNotification));
}
if (!isNil(receivedNotificationUserInfo)) {
store.dispatch(pushNotificationRegistered(receivedNotificationUserInfo));
}
if (!isNil(receivedIds)) {
store.dispatch(pushNotificationIdsReceived(receivedIds));
}
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('registered', this.onRegistered);
OneSignal.addEventListener('ids', this.onIds);
OneSignal.removeEventListener('opened', onOpened);
OneSignal.removeEventListener('received', onReceived);
OneSignal.removeEventListener('registered', onRegistered);
OneSignal.removeEventListener('ids', onIds);
this.setState({ isStoreInitialised: true });
});
}
componentWillUnmount() {
OneSignal.removeEventListener('opened', this.onOpened);
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('registered', this.onRegistered);
OneSignal.removeEventListener('ids', this.onIds);
OneSignal.removeEventListener('opened', onOpened);
OneSignal.removeEventListener('received', onReceived);
OneSignal.removeEventListener('registered', onRegistered);
OneSignal.removeEventListener('ids', onIds);
}
onOpened(openResult) {
this.store.dispatch(pushNotificationOpened(openResult));
}
onReceived(notification) {
this.store.dispatch(pushNotificationReceived(notification));
}
onRegistered(notificationUserInfo) {
this.store.dispatch(pushNotificationRegistered(notificationUserInfo));
}
onIds(ids) {
this.store.dispatch(pushNotificationIdsReceived(ids));
}
render() {
if (!this.state.isStoreInitialised) {
return <Blank />;
}
return (
<Provider store={this.store}>
<AppNavigator />
</Provider>
);
}
}
export default App;
์ฐธ๊ณ : configureStore
๋ Redux ์ ์ฅ์๋ฅผ ์์ฑํ๊ณ (์: createStore()
ํธ์ถ) redux-persist๋ฅผ ์ค์ ํ๋(์: persistStore()
ํธ์ถ) ํจ์์
๋๋ค. configureStore
๋ ์ฝ๋ฐฑ ํจ์๋ฅผ ๋งค๊ฐ ๋ณ์๋ก ์ฌ์ฉํ๊ณ persistStore
ํจ์์ onComplete
์ฝ๋ฐฑ์์ configureStore
์ ์ ๋ฌ๋ ์ฝ๋ฐฑ ํจ์๋ฅผ ํธ์ถํ๊ณ ์ ์ฅ์๋ฅผ ์ ๋ฌํฉ๋๋ค. ๊ฐ์ฒด๋ฅผ ์ด ์ฝ๋ฐฑ์ ๋ํ ๋งค๊ฐ๋ณ์๋ก ์ฌ์ฉํฉ๋๋ค. ๋ง์ง๋ง์ผ๋ก configureStore
๋ ์ ์ฅ์ ๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค.
๊ทธ๋์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ด ์คํ ์ด๊ฐ ์ค์ ๋๊ณ ์ฌ์ํ๋ ๋๊น์ง ๊ธฐ๋ค๋ฆฐ ๋ค์ ์ด๊ธฐ ์ด๋ฒคํธ ๋ฆฌ์ค๋์์ ์์ ํ ์ด๋ฒคํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์์ ์ ์ ๋ฌํ ๋ค์ ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ถ๊ฐํ๊ณ ์ด๊ธฐ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ ๊ฑฐํฉ๋๋ค.
@jordanmkoncz ์ฝ๋๋ฅผ ๊ณต์ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ์ฒ์์๋ ์ ์ ๊ฐ์ ์ค๋ฅ๊ฐ ์๋ ์ค ์์๋๋ฐ ๋ฌด์ ์๋ฆผ๊ณผ ๊ด๋ จ๋ ๋ฌธ์ ๋ผ๋ ๊ฒ์ ๊นจ๋ฌ์์ต๋๋ค. ์ ํ๋ฆฌ์ผ์ด์ ์ด ์ข ๋ฃ๋ ์ํ์์ ์๋ฆผ์ด ์ค๋ฉด ์กฐ์น๋ฅผ ์ทจํด์ผ ํฉ๋๋ค. ๊ทํ์ ์ฝ๋๊ฐ ์ ์๊ฒ ๋ง์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๊ฑฑ์ ๋ง์ธ์ @ccoeder. ์, ์ฑ์ด ๋ซํ ์ํ ์์ ์๋ฆผ์ ๋ํด ์ค์ ๋ก ์กฐ์น๋ฅผ ์ทจํ๋ ๋ฌธ์ ๋ ๋ค๋ฅธ ๋ฌธ์ ์ ๋๋ค. ์ด ๋ฌธ์ ๋ ํนํ ์ฑ์ด ์์๋ ๋(์ด์ ์ ์ ํ ์คํ๋์ง ์์์ ๋) ์ฌ์ฉ์๊ฐ ์ฑ์ ์ด๊ธฐ ์ํด ์๋ฆผ์ ํญํ์์ ์ฑ์์ ๊ฐ์งํ๋ ๊ฒ๊ณผ ๊ด๋ จ์ด ์์ต๋๋ค.
react-native-fcm์ด ์ด๋ป๊ฒ ์๋ํ๋์ง ์ดํด๋ณด์ธ์. getInitialNotification์ด๋ผ๋ ๋ฉ์๋๊ฐ ์์ต๋๋ค.
@jordanmkoncz ๊ฒ์ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค.
๋น์ทํ ๋ฌธ์ ๊ฐ์์์ต๋๋ค. ์ฑ์ด ํธ์ ์๋ฆผ์ ์์ ํ๋ฉด ํ๋ฉด์ด ์ํ๋ ํ๋ฉด์ผ๋ก ์ด๋ํฉ๋๋ค.
๊ทธ๋ฌ๋ ์๋ฆผ์ ์ด๋ฉด ํ์ ํธ์ ๊ธฐ๋ฅ์ด ์๋ํ์ง ์์ต๋๋ค.
์์:
componentWillMount() {
OneSignal.addEventListener('์์ ', this._onReceived);
OneSignal.addEventListener('์ด๋ฆผ', this._onOpened);
}
componentWillUnmount() {
OneSignal.removeEventListener('์์ ', this.__onReceived);
OneSignal.removeEventListener('์ด๋ฆผ', this._onOpened);
}
_onReceived(์๋ฆผ) {
console.log('์๋ฆผ ์์ : ', ์๋ฆผ); // ์ ์๋
this.props.navigator.push({ pushSreen, passProps : { ๋งค๊ฐ๋ณ์ } }); // ์ ์๋
}
_onOpened(์คํ ๊ฒฐ๊ณผ) {
console.log('์๋ฆผ ๋ณธ๋ฌธ: ', openResult.notification.payload.body); // ์ ์๋
this.props.navigator.push({ pushSreen, passProps : { ๋งค๊ฐ๋ณ์ } }); // ์๋ ์ํจ
}
์ด์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์ธ์? ๋น์ ์ด ๋๋ฅผ ๋์ธ ์ ์๋ค๋ฉด ์ฌ๊ธฐ์ ํ์ ๋ฐ๋๋๋ค. ๊ฐ์ฌ ํด์
ํ .. Redux Provider
์ ์์์ผ๋ก PushNotificationHelper
๊ตฌ์ฑ ์์๊ฐ ์์ต๋๋ค. ์ด ๊ตฌ์ฑ ์์๋ store
๊ฐ ์ฌ์ํ๋ ํ์๋ง ๋ ๋๋ง๋ฉ๋๋ค.
componentWillMount() {
AppState.addEventListener("change", this.handleAppStateChange);
OneSignal.configure({
onNotificationOpened: this.handleOpenNotification
});
OneSignal.addEventListener("received", this.onReceived);
OneSignal.addEventListener("opened", this.onOpened);
OneSignal.addEventListener("registered", this.onRegistered);
OneSignal.addEventListener("ids", this.onIds);
if (!IOS) {
OneSignal.inFocusDisplaying(0);
}
}
componentWillUnmount() {
AppState.removeEventListener("change", this.handleAppStateChange);
OneSignal.removeEventListener("received", this.onReceived);
OneSignal.removeEventListener("opened", this.onOpened);
OneSignal.removeEventListener("registered", this.onRegistered);
OneSignal.removeEventListener("ids", this.onIds);
}
handleOpenNotification = (message, data, isActive) => {
console.log("Notification", message, data, isActive);
if (isActive) {
// touchable banner displaying info from push notification
} else {
// act on data received from push notification
}
};
onReceived = notification => {
console.log("Notification received: ", notification);
};
onOpened = openResult => {
console.log("Message: ", openResult.notification.payload.body);
console.log("Data: ", openResult.notification.payload.additionalData);
console.log("isActive: ", openResult.notification.isAppInFocus);
console.log("openResult: ", openResult);
};
๋ด ์ฑ์ด ๋ซํ ๊ฒฝ์ฐ์๋( background
AppState๊ฐ ์๋๋ผ ์์ ํ ๋ซํ ์์) ํธ์ ์๋ฆผ์ ํญํ๋ฉด onOpened
๋ฉ์๋๊ฐ openResult
์ ํจ๊ป ํธ์ถ๋ฉ๋๋ค. ๊ฐ์ฒด ๋ฐ ๊ด๋ จ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ dispatch
redux ์์
์ ์ ์ ํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค.
@wkoutre ํฅ๋ฏธ๋กญ๋ค์. ํ์ฌ ์ฌ์ฉ ์ค์ธ react-native
, react-native-onesignal
๋ฑ์ ๋ฒ์ ์ ๊ฒ์ํ ์ ์์ต๋๊น? iOS์ Android ๋ชจ๋์์ ์ด๊ฒ์ ํ
์คํธ ํ์ต๋๊น? ํธ์ ์๋ฆผ์ ํญํ ๋ ์ฑ์ด ์์ ํ ๋ซํ ์ํ์์ ํธ์ ์๋ฆผ์ ํญํ์ฌ ์ฑ์ ์ฌ๋ ๊ด๋ฒ์ํ ํ
์คํธ๋ฅผ ์ํํ์ผ๋ฉฐ onOpened
๋ฉ์๋๊ฐ 100% ํธ์ถ๋๋ ๊ฒ์ ๋ฐ๊ฒฌํ์ต๋๊น?
PushNotificationHelper
์ ๋ก๋ฉ์ ์ธ์์ ์ผ๋ก ๋ ๋ฆ์ถ๋ ๊ฒฝ์ฐ, ์๋ฅผ ๋ค์ด 5์ด ์ ๋ ์ง์ฐ๋๋ setTimeout์ ๊ฐ๋ ๊ฒฝ์ฐ, ๊ทธ ํ PushNotificationHelper
๊ฐ ๋ง์ดํธ๋๊ณ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ OneSignal์ ๋ฑ๋กํ ์ ์๋๋ก ์ํ๋ฅผ ๋ณ๊ฒฝํ์๊ฒ ์ต๋๊น?
@jordanmkoncz
"react-native": "0.50.4"
"react-native-onesignal": "^3.0.7"
iOS์ Android ๋ชจ๋์์ ํ ์คํธํ์ต๋๋ค. ์. ๋ ๋ค 100%:
onOpened
๋ ํธ์ ์๋ฆผ์ ๋ฐ์ดํฐ๋ก ํธ์ถ๋๊ณ openResult.notification.isAppInFocus === false
setTimeout
ํ๊ณ ๋ค์ ์ฐ๋ฝ๋๋ฆฌ๊ฒ ์ต๋๋ค.
EDIT1: ์ ๋ ์๋ฌด๊ฒ๋ ๋ณ๊ฒฝํ์ง ์์์ผ๋ฉฐ ์ด์ ๋ Android์์ 100% ์คํจํฉ๋๋ค.
EDIT2: setTimeout
์ง์ฐ์ ์ํํ๋ฉด ํธ์ ์๋ฆผ์ ํญํ์ฌ ์ฑ ๋ก๋ ์ onOpened
๊ฐ ์คํ๋์ง ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๋ชจ๋ ๊ฒ์ App.js
์ ์๋ช
์ฃผ๊ธฐ ๋ฉ์๋๋ก ์ฎ๊ฒผ์ต๋๋ค -- index.ios.js
๋ฐ index.android.js
์ ๋ฑ๋ก๋ ๋ฃจํธ ๊ตฌ์ฑ ์์ -- ๊ทธ๋ฆฌ๊ณ onOpened
๋ 100%๋ผ๊ณ ํฉ๋๋ค. iOS์ ๊ฒฝ์ฐ ์๊ฐ์ ~50%, Android์ ๊ฒฝ์ฐ ์ฝ 50%์
๋๋ค.
Android๊ฐ ์ผ๊ด์ฑ์ด ์๋ ์ด์ ๋ ํ์คํ์ง ์์ง๋ง ๋ถ๋ช
ํ ๋ฌธ์ ์
๋๋ค. Android์์ ์ฑ์ด ์์ ํ ๋ซํ๊ณ ์๋ฆผ์ด ์์ ๋๋ฉด ๋๋ฒ๊ฑฐ๊ฐ ์ง์์ง๊ณ ํด๋์ค ์์ฒด๋ฅผ ์์ฑํ ๋๊น์ง ๋ด App.js
์ ์๋ ๋ชจ๋ ๊ฒ์ด ๋ก๋๋ฉ๋๋ค.
const IOSX = HEIGHT === 812 && PLATFORM === "ios";
const wrapperStyle = [Styles.flex1];
if (IOSX) wrapperStyle.push(Styles.backgroundDarkGray);
let SPLASH_TIME;
console.log(`Change to TRUE below to reset store state`);
const PURGE = DEV ? false : false;
if (DEV) SPLASH_TIME = 4000;
else SPLASH_TIME = 4000;
// const composeEnhancers = composeWithDevTools({
// realtime: true,
// port: 8000
// });
const composeEnhancers =
typeof window === "object" &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
DEV
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extensionโs options like name, actionsBlacklist, actionsCreators, serialize...
})
: compose;
const middlewares = [ReduxThunk];
// debugging tooling
// if (DEV) {
// // add logger
// middlewares.push(logger)
// // middlewares = [...middlewares, logger];
// middlewares = [...middlewares];
// replace these transient reducers when they've been created
export const store = createStore(
Reducers,
{},
composeEnhancers(
applyAppStateListener(),
applyMiddleware(...middlewares),
autoRehydrate()
)
);
// if (module.hot) {
// // Enable hot module replacement for reducers
// module.hot.accept(() => {
// const nextRootReducer = require("./reducers/index").default;
// store.replaceReducer(nextRootReducer);
// });
// }
console.log(`right before APP`);
// Debugger logs everything before this line.
export default class App extends Component {
...
}
@jordanmkoncz ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด ๋ณธ ์ ์ด ์๋์ง ๊ถ๊ธํฉ๋๋ค. https://github.com/wix/react-native-notifications
์ข์ต๋๋ค. iOS์ Android ๋ชจ๋์์ 100% ์๋ํ๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
๋ด App.js
์์ ๋ด ์ฑ ๊ตฌ์ฑ ์์๋ฅผ ์ ์ธํ๊ธฐ ์ ์ ๋ค์์ด ์์ต๋๋ค.
const handleOnOpened = openResult => {
store.dispatch(setInitialNotification(openResult));
};
OneSignal.configure({});
OneSignal.addEventListener("opened", handleOnOpened);
... ์ฌ๊ธฐ์ setInitialNotification
๋ ์ก์
์์ฑ์์
๋๋ค.
๊ทธ๋ฐ ๋ค์ (์ง๊ธ ํ์ฌ๋) ์ฑ์ด ์ฌ์ํ๋ฅผ ๋ง์น๋ฉด ๋ค์์ ํธ์ถํฉ๋๋ค.
this.setState({ rehydrated: true }, () => {
OneSignal.removeEventListener("opened", handleOnOpened);
});
๋ด ์ฑ -- redux Provider
๋ก ๋ํ๋ -- render
๋ฉ์๋์์ ๋ค์๊ณผ ๊ฐ์ด ๋ฐํ๋ฉ๋๋ค.
<Provider store={store}>
<IphoneXAwareView style={wrapperStyle}>
<StatusBar hidden={false} barStyle="light-content" />
<MyAlert />
<Loading />
<ConnectedAppWithNavigationState />
<PushNotificationHelper />
</IphoneXAwareView>
</Provider>
๊ฑฐ๊ธฐ์์ PushNotificationHelper
๊ตฌ์ฑ ์์๋ ๋ชจ๋ ํธ์ ์๋ฆผ์ ์์ ํ๊ณ ์ฒ๋ฆฌํฉ๋๋ค.
@bhoop ๋ช ๋ฌ์ด ์ง๋ฌ์ผ๋ฏ๋ก ์ฌ์ ํ ์์ ์ฌํญ์ ์ฐพ๊ณ ์๋์ง ํ์คํ์ง ์์ง๋ง... ๊ทธ๋ ๋ค๋ฉด ์๋ํด ๋ณด์ญ์์ค.
@wkoutre redux์ ๋ํ ์ด ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ํฌํจ๋ Readme ํ์ผ ์ ๋ฐ์ดํธ๋ก PR์ ์ค์ ํ ์ ์์ต๋๊น?
@avishayil ๋ฌผ๋ก ์ด์ฃ . ์ค๋ ์ ๋ ๊น์ง ๋์ฐฉํ๊ฒ ์ต๋๋ค
์๋น์ค์ผ PR์ด ๋ง๋ค์ด์ก์ต๋๋ค.
๋๋ ์ด๋ฐ ์๋ฆฌ๊ฐ ๋๋ ๋ฌธ์ ์ ์ง๋ฉดํด ์๋ค. ์ฑ์ด ์ด๋ฆฌ๋ฉด ์ฑ์ด ๋ฐฑ๊ทธ๋ผ์ด๋์ ์์ ๋๋ ๋ชจ๋ ์ฝ๋ฐฑ์ด ์ ์์ ์ผ๋ก ์คํ๋ฉ๋๋ค. ๊ทธ๋ฌ๋ ํธ์๋ฅผ ๋ฐ์ผ๋ฉด ๋ด ์ฑ ์์ด์ฝ์ด +1 ์ฆ๊ฐํ๊ณ ์์คํ ์ ์๋ฆผ ์ฝํ ์ธ ๊ฐ ์๋ ๋ฐฐ๋๋ฅผ ํ์ํ์ง๋ง ๋ฐฐ๋๋ฅผ ๋ฌด์ํ๊ณ ์์ด์ฝ(์๋ฆผ ๋ฐฐ๋๊ฐ ์๋)์ผ๋ก ์ฑ์ ์ด๋ฉด ์ฝ๋ฐฑ์ด ๋ฌด์๋ฉ๋๋ค. =[ ๋ฐฉ๋ฒ ์ด๊ฒ์ ์ฒ๋ฆฌ?
@brunoandradebr ์ด๊ฒ์ ์์๋๋ ๋์์ ๋๋ค. ์ฑ ์์ด์ฝ์์ ์ฑ์ ์ด๋ฉด ์์ ํ ์๋ฆผ์ด ๊ณ ๋ ค๋์ง ์์ต๋๋ค. ๊ทธ๊ฒ์ ๋จ์ง ์ฑ์ ์ฝ๋ ๋ค.
์ฌ์ฉ์๊ฐ ์๋ฆผ์ ์์ ํ๋์ง ์ฌ๋ถ์ ๋ฐ๋ผ ์ฑ์ด ์์๋ ๋์ ๋์์ ๋ณ๊ฒฝํ๋ ค๋ฉด ์์ ์ ์ง์ ํ์ธํด์ผ ํฉ๋๋ค.
๊ทธ๊ฒ์ ์ฌ์ค์ด ์๋๋๋ค. ์ฑ์ด ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํ ์ค์ผ ๋ ์์ด์ฝ์ผ๋ก ์ฑ์ ์ด๋ฉด ์ํ๋ ๋๋ก ํธ์ ์๋ฆผ์ ์ฒ๋ฆฌํฉ๋๋ค. ๋ฉ๋ชจ๋ฆฌ์์ ์ ๊ฑฐ(์ค์์ดํ)ํ ๋ค์ ์์ด์ฝ์ผ๋ก ์ด๋ฉด ์๋ฌด ์ผ๋ ์ผ์ด๋์ง ์์ต๋๋ค. ์กฐ์ฌ ์ค์ด์๊ณ XCode๊ฐ ์ฑ์ ์ค์งํ๊ณ oonesignal lib ๋งํฌ๋ฅผ ๋ซ๋๋ค๊ณ ์๊ฐํฉ๋๋ค.
@brunoandradebr ๊ทํ๊ฐ ๊ฒช๊ณ ์๋ ๋ฌธ์ ์ ์ด๋ค ์ฝ๋ฐฑ์ ์ธ๊ธํ๊ณ ์๋์ง ์คํดํ ์ ์์ต๋๋ค.
์ฑ์ด ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํ๋๋ ๊ฒฝ์ฐ received
์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ์ฑ์ด ์ข
๋ฃ๋๋ฉด ์ด๋ค ์ด๋ฒคํธ๋ ์์ ํ ์ ์์ต๋๋ค. ์๋ฆผ์ด ์ฑ๊ณผ ์ํธ ์์ฉํ ์ ์๋ ์ ์ผํ ๋ฐฉ๋ฒ(์ต์ํ iOS์ ๊ฒฝ์ฐ)์ ์ด๋ค ๋ฐฉ์์ผ๋ก๋ ์๋ฆผ๊ณผ ์ํธ ์์ฉํ๋ ๊ฒ์
๋๋ค.
์ฑ์ ์ข ๋ฃํ๊ณ ์๋ฆผ์ด ์์ ๋ ์์ด์ฝ์ผ๋ก ์ฑ์ ์ด๋ฉด ์ฑ์ด ์ฝ๋ฐฑ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ ์ ์์ง๋ง ์ฑ์ด ๋ฐฑ๊ทธ๋ผ์ด๋์์ ์คํ ์ค์ด๊ณ ์์ด์ฝ์ผ๋ก ์ด๋ฉด ์์๋๋ก ์ฝ๋ฐฑ์ด ์คํ๋ฉ๋๋ค. ์์์ด์ ?
@brunoandradebr ๋๋ ๊ทธ๊ฒ์ ์ป์๋ค๊ณ ์๊ฐํ๊ณ , ๋ด๊ฐ ํ๋ฆฌ์ง ์๋ค๋ฉด ๊ทธ๊ฒ์ ๋ด๊ฐ ์ด์ ์ฝ๋ฉํธ์์ ์ค๋ช ํ ํ๋์ ๋๋ค. ์ด์จ๋ , ๋๋ ์ด๊ฒ์ด ์ฃผ์ ์์ ๋ฒ์ด๋ฌ๋ค๊ณ ์๊ฐํ๋ฉฐ ์ด๊ฒ์ ๋ฌธ์ ๊ฐ ์๋ค๊ณ ์๊ฐ๋๋ฉด repo์์ ๋ณ๋์ ๋ฌธ์ ๋ฅผ ์ด์ด์ผ ํฉ๋๋ค.
@jordanmkoncz ๋ฐ์ ๋ค์ดํฐ๋ธ onesignal ๋ฌธ์ ์ ๋ํด ์ ๋ง ์ ์ดํดํ๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ด๊ฐ ์ฌ์ฉํ๋ ๋ฒ์ ์ react-native-onesignal: ^3.2.8 ๋ฐ react-native: 0.56.0์ ๋๋ค. ๋ฐฑ๊ทธ๋ผ์ด๋ ๋ฐ ํฌ๊ทธ๋ผ์ด๋์์ ์ฒ๋ฆฌ ์๋ฆผ์ ๊ตฌํํ ์ ์์์ง๋ง ์ง๊ธ ์ฑ์ด ๋ซํ๊ณ ์๋ฆผ์ ํญํ ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ฑ์ ๋ซ๊ณ ๋ค์ ์์ํ์ง ์๋ ํ ์ฌ๋ผ์ง์ง ์๋ ๋น ํฐ์ ํ๋ฉด๋ง ์ฑ์ ํ์๋ฉ๋๋ค. OneSignal์ ์น์ฌ์ดํธ์์ ๋ฌธ์๋ฅผ ์ฐพ์ ์ ์๊ธฐ ๋๋ฌธ์ ์ด ์ํฉ์ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ฐฐ์ฐ๊ณ ๊ตฌํํ๋ ๋ฐ ์๊ฐ์ ๋ณด๋๊ธฐ ๋๋ฌธ์ ์ค๋ง์ค๋ฝ์ต๋๋ค. ์ด์ ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ด ๋งค์ฐ ์ค์ํ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ์ฒ๋ฆฌํ ์ ์์์ง ํ์ ํ ์ ์์ต๋๋ค. ์์์ index.js์์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ๊ตฌํํ๋ ๊ฐ๋ฅํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฝ์์ง๋ง ๋ฐ์ ํ์์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์ค์ฒฉ๋ ์คํ ํ๋ฉด์ผ๋ก ์ด๋ํ๋ ค๋ฉด App.js์ ์ ์ธ๋ ๊ธฐ๋ณธ ํ์๊ธฐ์์ ์ฐธ์กฐ๋ฅผ ๊ฐ์ ธ์์ผ ํฉ๋๋ค. ์ด ๋ฌธ์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋ํด ์กฐ์ธ์ ์ฃผ์๋ฉด ์ ๋ง ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. ๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ ์๊ฒ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๊ณ ๋ค๋ฅธ ๋ง์ ๋ถ๋ค๋ ์ด ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ด๊ฐ ์ฐพ์ ์ผ๋ถ ๊ด๋ จ/์ค๋ณต ๋ฌธ์ ์๋ https://github.com/geektimecoil/react-native-onesignal/issues/206 , https://github.com/geektimecoil/react-native-onesignal/issues/195 , https://github.com/geektimecoil/react-native-onesignal/issues/191 , https://github.com/geektimecoil/react-native-onesignal/issues/336 , https://github.com/geektimecoil/ react-native-onesignal/issues/334 , https://github.com/geektimecoil/react-native-onesignal/issues/264 , https://github.com/geektimecoil/react-native-onesignal/issues/279.
์ด ๋ฌธ์ ๋ ๋ชจ๋ ํธ์ ์๋ฆผ์ ๋๋ฌ ์ฑ์ ์ด ๋
opened
์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ํธ์ถ๋์ง ์๊ณ ์ฑ์ด ์คํ ๋์ง ์๋ ์ด ๋ฌธ์ ์ ๋ํ ๊ฒ ๊ฐ์ต๋๋ค. ํด๋น ๋ฌธ์ ์ ๋ด๊ฐ ์ํํ ํ ์คํธ์์ ์ฝ์ ๋ด์ฉ์ ๋ฐ๋ฅด๋ฉด ์ด ๋ฌธ์ ์ ์์ธ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก์ด ์ด๋ค ์์ผ๋ก๋ ์ง์ฐ๋๋ ๊ฒ ๊ฐ์ต๋๋ค(์:OneSignal.addEventListener('opened', this.onOpened);
๋ ์ฑ ์์ฒด๊ฐ ๋ก๋๋จ). ์ด๊ฒ์ React ๊ตฌ์ฑ ์์ ๋ด์ ์ด ์ฝ๋๊ฐ ์๊ธฐ ๋๋ฌธ์ผ ์ ์์ต๋๋ค(์:constructor
๋๋componentWillMount
๋๋componentDidMount
ํจ์) ๋๋ ๊ตฌ์ฑ/์ฌ์ํ ํ๊น์ง ํธ์ถ๋์ง ์๊ธฐ ๋๋ฌธ์ผ ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ์ด ์ง์ฐ์ผ๋ก ์ธํด ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋๊ธฐ ์ ์ react-native-onesignal์ ์ํด ์ด๋ฒคํธ ์์ฒด(์๋ฆผ์ด ์ด๋ ธ์)๊ฐ ๋ฐ์ํ๊ณ ์ด ์์ ์์ ์ด๋ฒคํธ๋ฅผ ๋์ณค๊ณ ๋์๋์ง ์ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค. ์ฐธ๊ณ ๋ก ์ด ๋์ผํ ๋ฌธ์ ๋ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฆฌ์ค๋(์:ids
์ด๋ฒคํธ ๋ฆฌ์ค๋)์ ์ํฅ์ ๋ฏธ์นฉ๋๋ค.๊ฐ๋ฅํ ํ ๋นจ๋ฆฌ ๋ฐ์ํ๋๋ก ์ด ์ฝ๋๋ฅผ ์ด๋ํ๋ฉด ์ด๋ฒคํธ๊ฐ ์์๋๊ธฐ ์ ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋์ด ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๊ฐ ํธ์ถ๋๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. ์๋ฅผ ๋ค์ด ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก ์ฝ๋๋ฅผ
index.ios.js
ํ์ผ๋ก ์ด๋ํ๊ฑฐ๋index.ios.js
ํ์ผ์ด ๋จ์ํ ๊ฐ์ ธ์ค๊ธฐ๋ง ํ๋ ๊ฒฝ์ฐApp.js
ํ์ผ์ ์์ ๋ถ๋ถ์ผ๋ก ์ด๋ํด์ผ ํฉ๋๋ค.App
๊ตฌ์ฑ ์์๋ฅผ ๋ง๋ค๊ณ ๋ฑ๋กํฉ๋๋ค(AppRegistry.registerComponent
๋ฅผ ํตํด).์ด ์ค์ ์ด ์๋ฃ๋๋ฉด ์ด์ ์๋ฆผ์ด ์ด๋ฆฐ ์ด๋ฒคํธ๋ฅผ ์บก์ฒํ ์ ์์ผ๋ฉฐ ์ด๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์ฑ ์ค์ ๋ฐฉ๋ฒ(์: ์ฌ์ฉ ์ค์ธ์ง ์ฌ๋ถ์ ๋ฐ๋ผ ๋ค๋ฆ ๋๋ค. Redux, ๋๋ redux-persist๋ฅผ ์ฌ์ฉ ์ค์ธ์ง ์ฌ๋ถ ๋ฑ).
๋ด ํ์ฌ ์๋ฃจ์ ์ ๋ด
App.js
ํ์ผ ์์ฒด์ ์ต์์ ์์ค์์ ์ ์๋ ๋ณ์์ ์๋ฆผ์ ์ ์ฅํ๋ ๊ฒ์ ๋๋ค(๋ดApp
๊ตฌ์ฑ ์์๋ฅผ ์ ์ธํ๊ธฐ ์ ์๋). ๊ทธ๋ฐ ๋ค์ ์ด๊ธฐํ๋ฅผ ์๋ฃํ๋ฉด ๋ด Redux ์คํ ์ด(redux-persist์ ์ํ ๋ด ์คํ ์ด์ ์ฌ์ํ ๋๊ธฐ ํฌํจ), ํ์ด๋ก๋๋ก ์๋ฆผ์ ์ฌ์ฉํ์ฌ ์์ ์ ๋ฐ์กํ๊ณ (์๋ฆผ์ด ์ด๋ฆฐ ๊ฒฝ์ฐ) ์ต์์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ ์ ๊ฑฐํ๊ณ ์ ์ด๋ฒคํธ๋ฅผ ์ถ๊ฐํฉ๋๋ค. ๋ดApp
๊ตฌ์ฑ ์์ ์์ฒด์ ๋ฆฌ์ค๋(์ด ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ ์๋ฆผ, ์ฅ์น ID ๋ฑ์ ์ก์ ํ์ด๋ก๋๋ก ์ฌ์ฉํ์ฌ Redux ์ ์ฅ์์ ์ก์ ์ ์ ๋ฌํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค).์ด ์๋ฃจ์ ์ ๋ถ๋ช ํ ๋งค์ฐ ํดํคํ๊ณ ์ด๊ฒ์ด ์์๋๋ก ์๋ํ์ง ์๋ ์ผ๋ถ ๊ทน๋จ์ ์ธ ๊ฒฝ์ฐ๊ฐ ์์ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ react-native-onesignal์์ ์ ์ ํ ์๋ฃจ์ ์ด ๊ตฌํ๋ ๋๊น์ง ์ด๊ฒ์ ์ ์ ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๊ธฐ ์ ์ ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ฅผ ์ค์ ํ ๋๊น์ง ๊ธฐ๋ค๋ฆฌ๋๋ก react-native-onesignal์ด ์ ๋ฐ์ดํธ๋์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ํ ๊ฐ์ง ๊ฐ๋ฅํ ์๋ฃจ์ ์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ฉด(์:
opened
์ด๋ฒคํธ) ์ด๋ฒคํธ๊ฐ ๋๊ธฐ์ด์ ๋ค์ด๊ฐ๊ณ react-native-onesignal์ด ํ์ฌ ๋ฑ๋ก๋ ํด๋น ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ์๋์ง ํ์ธํ๋ ๊ฒ์ ๋๋ค. ์๋ ๊ฒฝ์ฐ ๋๊ธฐ์ด์ ์ด๋ฒคํธ๋ฅผ ๋จ๊ฒจ๋ก๋๋ค. ๊ทธ๋ฐ ๋ค์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋์๋ง์ ์ด ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ์์ ํ ์ด๋ฒคํธ๊ฐ ์์๋๊ณ ํ์์ ์ ๊ฑฐ๋ฉ๋๋ค. ๊ทธ๋ ๊ฒ ํ๋ฉด ์ฑ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋๋ฅผ ์ธ์ ๋ ์ง ์ถ๊ฐํ ์ ์์ต๋๋ค(์: Redux ์คํ ์ด๊ฐ ๊ตฌ์ฑ๋๊ณ ์ฌ์ํ๋๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฐ ํ, ์ฑ ์์ฒด๊ฐ ๋ก๋๋ ํ 1-2์ด๊ฐ ๋ ์ ์์). ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋๋ฉด ์ด๋ฒคํธ ํธ๋ค๋ฌ ํจ์๊ฐ ํธ์ถ๋๊ณ ๋ฐ์ํ ์ด๋ฒคํธ(์: ์๋ฆผ์ด ์ด๋ฆฐ ์ด๋ฒคํธ)๋ฅผ ์์ ํฉ๋๋ค.์ฌ์ฉ์๊ฐ ํธ์ ์๋ฆผ์ ํญํ๊ธฐ ๋๋ฌธ์ ์ฑ์ด ์ด๋ ธ์์ ์ ์ด๋ ๊ฐ์งํ๊ธฐ ์ํ ๋ ๋ค๋ฅธ ๊ฐ๋ฅํ ์๋ฃจ์ ์ ์ ์ํ ๋๋ก
getInitialNotification()
fromPushNotificationIOS
์ ์ ์ฌํ ์์ ์ ์ํํ๋ ๊ฒ์ ๋๋ค. ์ธ์ ๋ ์ง ํด๋น ๊ธฐ๋ฅ์ ํธ์ถํ๋ฉด ์ฌ์ฉ์๊ฐ ์ฑ์ ์ด๊ธฐ ์ํด ํญํ ํธ์ ์๋ฆผ์ ๋ฐํํฉ๋๋ค(๋๋ ์ด๊ฒ์ด ๋ฐ์ํ์ง ์์ ๊ฒฝ์ฐnull
). ๊ทธ๋ฌ๋ ์ด๊ฒ์ด react-native-onesignal์์ ๊ตฌํ๋๋๋ผ๋ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฆฌ์ค๋(์:ids
์ด๋ฒคํธ ๋ฆฌ์ค๋)์ ์ํฅ์ ๋ฏธ์น๋ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์๋ฌด ๊ฒ๋ ํ์ง ์์ต๋๋ค.๋ฐ๋ผ์ ํด๋น ์ด๋ฒคํธ ๋ฆฌ์ค๋๊ฐ ๋ฑ๋ก๋๊ธฐ ์ ์ ๋ฐ์ํ๋ ์ด๋ฒคํธ์ ํต์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ฌ ์ฑ์์ ์ด๋ฒคํธ๋ฅผ ๋์น๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ์๋ฃจ์ ์ด ์ ๋ง๋ก ํ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.