ExperienceNotificationService

사용되지 않는 항목 표시
만들 수 없음
서비스
복제되지 않음

Experience Notifications are a way for 13+ users to keep up with their favorite experiences through timely, personalized notifications. This service contains methods to validate users and prompt them to enable notifications.

요약

메서드

  • Shows an in-experience prompt for the local player to enable notifications.

  • Indicates whether the local player can be prompted to enable notifications.

이벤트

속성

메서드

PromptOptIn

void

PromptOptIn() prompts the local player to enable notifications through an in-experience modal. You should always use the result of CanPromptOptInAsync() before calling this method since the ability to be prompted depends on various factors like the player's age or whether they've already enabled notifications for your experience.

This method always infers the local player (Players.LocalPlayer) and it can only be called from a LocalScript or from a Script with RunContext set to Client.

See Experience Notifications for more details on implementing and customizing notifications, using launch data, and more.


반환

void

코드 샘플

LocalScript - Notification Permission Prompt Implementation

local ExperienceNotificationService = game:GetService("ExperienceNotificationService")
-- Function to check whether the player can be prompted to enable notifications
local function canPromptOptIn()
local success, canPrompt = pcall(function()
return ExperienceNotificationService:CanPromptOptInAsync()
end)
return success and canPrompt
end
local canPrompt = canPromptOptIn()
if canPrompt then
local success, errorMessage = pcall(function()
ExperienceNotificationService:PromptOptIn()
end)
end
-- Listen to opt-in prompt closed event
ExperienceNotificationService.OptInPromptClosed:Connect(function()
print("Opt-in prompt closed")
end)

CanPromptOptInAsync

생성

CanPromptOptInAsync() returns true if the local player can be prompted to enable notifications. You should always use the result of this method before calling PromptOptIn() since the ability to be prompted depends on various factors like the player's age or whether they've already enabled notifications for your experience.

This method always infers the local player (Players.LocalPlayer) and it can only be called from a LocalScript or from a Script with RunContext set to Client. It should also be called in a pcall() since it's an asynchronous network call that may occasionally fail.

See Experience Notifications for more details on implementing and customizing notifications, using launch data, and more.


반환

Whether the local player can be prompted to enable notifications.

코드 샘플

LocalScript - Notification Permission Prompt Implementation

local ExperienceNotificationService = game:GetService("ExperienceNotificationService")
-- Function to check whether the player can be prompted to enable notifications
local function canPromptOptIn()
local success, canPrompt = pcall(function()
return ExperienceNotificationService:CanPromptOptInAsync()
end)
return success and canPrompt
end
local canPrompt = canPromptOptIn()
if canPrompt then
local success, errorMessage = pcall(function()
ExperienceNotificationService:PromptOptIn()
end)
end
-- Listen to opt-in prompt closed event
ExperienceNotificationService.OptInPromptClosed:Connect(function()
print("Opt-in prompt closed")
end)

이벤트

OptInPromptClosed

This event fires when the local player closes a prompt that was displayed through PromptOptIn(). It can only be connected in a LocalScript or in a Script with RunContext set to Client.

See Experience Notifications for more details on implementing and customizing notifications, using launch data, and more.


코드 샘플

LocalScript - Notification Permission Prompt Implementation

local ExperienceNotificationService = game:GetService("ExperienceNotificationService")
-- Function to check whether the player can be prompted to enable notifications
local function canPromptOptIn()
local success, canPrompt = pcall(function()
return ExperienceNotificationService:CanPromptOptInAsync()
end)
return success and canPrompt
end
local canPrompt = canPromptOptIn()
if canPrompt then
local success, errorMessage = pcall(function()
ExperienceNotificationService:PromptOptIn()
end)
end
-- Listen to opt-in prompt closed event
ExperienceNotificationService.OptInPromptClosed:Connect(function()
print("Opt-in prompt closed")
end)