์ค๋ช
:
Freschat SDK๋ฅผ ์ฌ์ฉํ์ฌ AppDelegate.m ๋ด์์ ํธ์ ์๋ฆผ์ ์ฒ๋ฆฌํ๋ ค๊ณ ํ๋๋ฐ onesignal ์๋น์ค ํ์ฅ์์ ์๋ํ์ง ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
ํ๊ฒฝ
๋ฌธ์ ์ฌํ ๋จ๊ณ:
npm์ ์ฌ์ฉํ์ฌ OneSignal SDK๋ฅผ ํ๋ก์ ํธ์ ์ค์นํฉ๋๋ค.
๊ธฐํ:
(ํฌ๋์ ์คํ ์ถ์ ๋ฐ ๊ธฐํ ์ ๋ณด๋ ์ฌ๊ธฐ์ ์์)
@nitish1099 "์์๊ทธ๋ ์๋น์ค ํ์ฅ์ด ์ ๋๋ ๊ฒ ๊ฐ๋ค"๋
๋ํ Freschat์ SDK๋ ๋น๊ณต๊ฐ ์์ค์ด๋ฏ๋ก ๋ถํํ๋ ๋นํธํ์ฑ์ ๋๋ฒ๊น ํ๋ ์ธก๋ฉด์์ ์ฐ๋ฆฌ๊ฐ ํ ์ ์๋ ์ผ์ ๋ง์ง ์์ต๋๋ค. ํ๋ก์ ํธ์์ SDK๋ฅผ ์ ๊ฑฐํ๋ฉด AppDelegate ๋ฉ์๋๊ฐ ํธ์ถ๋ฉ๋๊น?
์๋ฆผ ์ด๋ฒคํธ ๋ฉ์๋ ํธ์ถ์ ์์ ํ๋ ค๋ฉด ๋์ UNUserNotificationCenterDelegate
๋ฉ์๋๋ฅผ ์ฌ์ฉํด์ผ ํ ์๋ ์์ต๋๋ค.
@Nightsd01 ๋ค์ดํฐ๋ธ ๊ฐ๋ฐ์๊ฐ ์๋ ๊ฒฝ์ฐ ์๋ฆผ ์๋น์ค ํ์ฅ์ด didReceiveRemoteNotification์ ์ฌ์ ์ํ๋์ง ์๋ ค์ฃผ์ค ์ ์๋์? ๋ํ UNUserNotificationCenterDelegate๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ด๋ ์ฐธ์กฐํ ์ ์๋ ๊ฐ์ด๋๋ฅผ ๊ณต์ ํ ์ ์๋์ง ์๋ ค์ฃผ์ค ์ ์์ต๋๋ค.
@Nightsd01 ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น?
์ฌ๊ธฐ์ (๋งค์ฐ) ์๋ต์ด ๋ฆ์ด์ ์ฃ์กํ์ง๋ง ๋ช ๊ฐ์ง ์ฌํญ์ด ์์ต๋๋ค.
์ฐ์ application:didReceiveRemoteNotification:
๋ ๋ ์ด์ ์ฌ์ฉ๋์ง ์์ต๋๋ค. ๋์ application:didReceiveRemoteNotification:fetchCompletionHandler:
๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์ ๊ฒ์
๋๋ค. ํ์ง๋ง ์ด ๋ฐฉ๋ฒ๋ ์ฌ์ฉํ์ง ์๋ ๊ฒ์ด ์ข์ต๋๋ค. ์๋ฆผ์ ๋ฐ์์ ๋ ๋ค์ดํฐ๋ธ ์ฝ๋๋ฅผ ์คํํ๋ ค๋ฉด UNUserNotificationCenterDelegate
๋ฉ์๋๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
์๋ฆผ ์๋น์ค ํ์ฅ์ ์ด ๋ฉ์๋๋ฅผ ์ฌ์ ์ํ์ง ์์ต๋๋ค.
์ฉ๋์ UNUserNotificationCenterDelegate
, ํธ์ง AppDelegate.h
์ถ๊ฐํฉ๋๋ค :
#import <UserNotifications/UserNotifications.h>
๊ทธ๋ฐ ๋ค์ AppDelegate ์ธํฐํ์ด์ค๋ฅผ ๋ณ๊ฒฝํ์ฌ UNUserNotificationCenterDelegate
ํ๋กํ ์ฝ์ ๊ตฌํํฉ๋๋ค.
<strong i="18">@interface</strong> AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate>
์์ AppDelegate.m
๋ด๋ถ์ didFinishLaunchingWithOptions:
๋ฐฉ๋ฒ, ๋ค์๊ณผ ๊ฐ์ ์ค์ ์ถ๊ฐํ๋ค :
UNUserNotificationCenter.currentNotificationCenter.delegate = self;
๋ง์ง๋ง์ผ๋ก ์๋ฆผ์ด ์์ ๋ ๋๋ง๋ค ํธ์ถ๋๋ ๋ค์ ๋ฉ์๋๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
//do stuff
}
SDK์ ๋ฌธ์ ๊ฐ ์๋๋ฏ๋ก ์ข ๋ฃ
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฌ๊ธฐ์ (๋งค์ฐ) ์๋ต์ด ๋ฆ์ด์ ์ฃ์กํ์ง๋ง ๋ช ๊ฐ์ง ์ฌํญ์ด ์์ต๋๋ค.
์ฐ์
application:didReceiveRemoteNotification:
๋ ๋ ์ด์ ์ฌ์ฉ๋์ง ์์ต๋๋ค. ๋์application:didReceiveRemoteNotification:fetchCompletionHandler:
๋ฅผ ์ฌ์ฉํ๊ณ ์ถ์ ๊ฒ์ ๋๋ค. ํ์ง๋ง ์ด ๋ฐฉ๋ฒ๋ ์ฌ์ฉํ์ง ์๋ ๊ฒ์ด ์ข์ต๋๋ค. ์๋ฆผ์ ๋ฐ์์ ๋ ๋ค์ดํฐ๋ธ ์ฝ๋๋ฅผ ์คํํ๋ ค๋ฉดUNUserNotificationCenterDelegate
๋ฉ์๋๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.์๋ฆผ ์๋น์ค ํ์ฅ์ ์ด ๋ฉ์๋๋ฅผ ์ฌ์ ์ํ์ง ์์ต๋๋ค.
์ฉ๋์
UNUserNotificationCenterDelegate
, ํธ์งAppDelegate.h
์ถ๊ฐํฉ๋๋ค :๊ทธ๋ฐ ๋ค์ AppDelegate ์ธํฐํ์ด์ค๋ฅผ ๋ณ๊ฒฝํ์ฌ
UNUserNotificationCenterDelegate
ํ๋กํ ์ฝ์ ๊ตฌํํฉ๋๋ค.์์
AppDelegate.m
๋ด๋ถ์didFinishLaunchingWithOptions:
๋ฐฉ๋ฒ, ๋ค์๊ณผ ๊ฐ์ ์ค์ ์ถ๊ฐํ๋ค :๋ง์ง๋ง์ผ๋ก ์๋ฆผ์ด ์์ ๋ ๋๋ง๋ค ํธ์ถ๋๋ ๋ค์ ๋ฉ์๋๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
SDK์ ๋ฌธ์ ๊ฐ ์๋๋ฏ๋ก ์ข ๋ฃ