Notice»

Recent Post»

Recent Comment»

Recent Trackback»

Archive»

« 2024/3 »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

5 NotificationsExtensions 소개

 

앞에서 타일 알림과 배지, 토스트를 통해 템플릿을 사용하는 방법을 배웠다. 알림에 공통된 XML 구조를 사용하여 푸쉬 알림에서도 공통된 구조를 사용한 부분은 추후에 확장성까지 고려한 부분이라 설계가 잘되어 있다고 볼 수 있다. 하지만 XML 코드를 추가, 수정하기 위해 XML라이브러리를 이용하고 문자열을 편집하는 방법은 좀 불편한 게 사실이다. 다행히 MSDN에 있는 타일 관련 샘플 예제에 NotificationsExtensions 라이브러리가 포함되어 있는데 이 라이브러리에는 각 템플릿 별로 클래스가 잘 만들어져 있어 XML 코드를 입력할 필요가 없다. 이장의 샘플 예제를 통해 앞서 소개 했던 예제들을 기본 XML 코드를 이용하는 방법과 NotificationsExtensions을 이용하는 코드로 정리해 놓았으므로 적극 활용하면 될 것 같다. 이 라이브러리가 다음 버전에서는 API로 정리가 되서 좀 더 편리하게 사용될 것이라고 생각한다.

 

위의 알림 예제들을 NotificationsExtensions로 변경한 예제이다.

 

[예제 11] NotificationsExtensions 사용

// [예제 2] 타일 템플릿 사용

private void SendTile_Click(object sender, RoutedEventArgs e)

{

    // 정사각형 타일만 적용

    ITileSquareText03 tileContent = TileContentFactory.CreateTileSquareText03();

    tileContent.TextBody1.Text = "타일 업데이트";

     TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());

}

 

// [예제 3] 정사각형과 와이드 타일 업데이트

private void SendAllTile_Click(object sender, RoutedEventArgs e)

{

    ITileWideImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01();

    tileContent.Image.Src = "ms-appx:///images/blueWide.png";

    tileContent.Image.Alt = "BlueWide image";

 

    ITileSquareImage squareContent = TileContentFactory.CreateTileSquareImage();

    squareContent.Image.Src = "ms-appx:///images/blueSquare.png";

    squareContent.Image.Alt = "BlueSqure image";

    tileContent.SquareContent = squareContent;

 

    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification());

}

 

// [예제 5] 배지 템플릿 구조 사용

private void SendBadge_Click(object sender, RoutedEventArgs e)

{

    BadgeGlyphNotificationContent badgeContent = new BadgeGlyphNotificationContent((GlyphValue)6);

  BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update(badgeContent.CreateNotification());

}

 

// [예제 7] 보조 타일 생성

private async void PinLiveTile_Click(object sender, RoutedEventArgs e)

{

    SecondaryTile secondaryTile = new SecondaryTile(TileId,

                                 "보조 타일",

                                 "보조 타일 샘플",

                                 DateTime.Now.ToLocalTime().ToString(),

                                 TileOptions.ShowNameOnLogo | TileOptions.ShowNameOnWideLogo,

                                 new Uri("ms-appx:///images/redSquare.png"),

                                 new Uri("ms-appx:///images/redWide.png"));

 

    secondaryTile.ForegroundText = ForegroundText.Light;

 

    // 보조 타일 추가 확인

    bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Below);

 

    if (isPinned)

    {

        // 보조 타일 추가 성공

    }

    else

    {

        // 보조 타일 추가 실패

    }

}

 

// [예제 8] 보조 타일 알림

private void SendTileNotification_Click(object sender, RoutedEventArgs e)

{

    if (SecondaryTile.Exists(TileId))

    {

        ITileWideText04 tileContent = TileContentFactory.CreateTileWideText04();

        tileContent.TextBodyWrap.Text = "보조 타일 업데이트";

 

        ITileSquareText04 squareContent = TileContentFactory.CreateTileSquareText04();

        squareContent.TextBodyWrap.Text = "보조 타일 업데이트";

        tileContent.SquareContent = squareContent;

        TileUpdateManager.CreateTileUpdaterForSecondaryTile(TileId).Update(tileContent.CreateNotification());

    }

}

 

// [예제 8] 보조 타일 알림

private void SendBadgeNotification_Click(object sender, RoutedEventArgs e)

{

    if (SecondaryTile.Exists(TileId))

    {

        BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent(6);

        BadgeUpdateManager.CreateBadgeUpdaterForSecondaryTile(TileId).Update(badgeContent.CreateNotification());

    }

}

 

// [예제 9] 토스트 알림

private void SendToast_Click(object sender, RoutedEventArgs e)

{

    IToastText01 templateContent = ToastContentFactory.CreateToastText01();

    templateContent.TextBodyWrap.Text = "토스트 알림";

    IToastNotificationContent toastContent = templateContent;

 

    ToastNotification toast = toastContent.CreateNotification();

    ToastNotificationManager.CreateToastNotifier().Show(toast);

}

 

// [예제 10] 장기 알림 반복 오디오

private void SendLongToastLoopingAudio_Click(object sender, RoutedEventArgs e)

{

    IToastText02 toastContent = ToastContentFactory.CreateToastText02();

    toastContent.Duration = ToastDuration.Long;

    toastContent.TextHeading.Text = "장기 알림";

    toastContent.Audio.Loop = true;

    toastContent.Audio.Content = ToastAudioContent.LoopingAlarm;

    toastContent.TextBodyWrap.Text = "반복 오디오";

 

    ToastNotification toast = toastContent.CreateNotification();

    ToastNotificationManager.CreateToastNotifier().Show(toast);

}

 

 

 

 

: