← 모든 확장

네이티브 확장

KlugPush

com.klug.push.Push

APM이 필요 없습니다. 다운로드해서 바로 사용하세요. 이보다 더 간단할 수 없습니다.

Mac의 AIR 앱을 위한 원격 푸시 알림으로, 실시간 권한 상태 확인과 시스템 설정 바로가기를 제공합니다.

macOS 프로덕션 운영 중 연 €19부터 · 구매

개요

KlugPush는 macOS의 AIR 앱에 원격 푸시 알림을 제공합니다. 앱을 Apple의 푸시 알림 서비스에 등록하고, 서버용 기기 토큰을 제공하며, 수신한 알림을 ActionScript로 전달합니다.

macOS에서는 한 번 알림을 거부한 사용자에게 다시 묻지 않습니다. 따라서 KlugPush는 언제든 현재 권한 상태를 보고하고 시스템 설정의 알림 페이지를 열어, 사용자가 나중에 알림을 켤 수 있게 합니다.

KlugPush는 개념 증명인 저희 앱의 Mac 버전에서 매일 사용되고 있습니다.

기능

  • 독립형: ANE 하나로 충분하며, 코어 라이브러리나 의존성 ANE를 추가할 필요가 없음
  • 권한을 요청하고 원격 알림에 등록
  • 등록이 끝나는 즉시 서버용 기기 토큰 제공
  • 수신한 알림을 JSON으로 ActionScript에 전달
  • 실시간 권한 상태: 미결정, 거부됨, 허용됨
  • 시스템 설정의 알림 페이지를 바로 엶
  • Apple의 푸시 서비스를 통해 직접 전송되며, 별도의 푸시 제공업체가 필요 없음

지원 플랫폼

macOS Apple silicon · Intel

다른 플랫폼에서는 isSupported가 false를 반환하므로 동일한 코드를 크로스 플랫폼 앱에 그대로 둘 수 있습니다.

시작하기

애플리케이션 디스크립터에 확장을 추가합니다:

app.xml
<extensions>
    <extensionID>com.klug.push.Push</extensionID>
</extensions>

앱은 푸시 알림 entitlement와 Push Notifications 기능이 포함된 프로비저닝 프로파일로 서명되어야 합니다.

코드 예제

저희 앱의 Mac 버전에서 실행되는 API에서 가져온 네 가지 완전한 흐름입니다. 모든 호출은 즉시 반환되며, 결과는 콜백과 StatusEvent로 전달됩니다. 전체 문서 →

1 · 등록하고 토큰을 서버로 전송
Push.as
import com.klug.push.Push;

var push:Push = Push.getInstance();

if ( push.isSupported )   // macOS; false on every other platform
{
    // asks for permission on the first start, then registers with Apple's push service.
    // The token also arrives when the user declines: permission only affects the display.
    push.register( onToken, onPushError, onNotification );
}

function onToken( token:String ):void
{
    if ( token != loadSavedToken() )   // your app functions
        sendTokenToServer( token );    // e.g. a POST to https://your.server/push
}

function onPushError( message:String ):void
{
    // typical cause: the app is not signed with the push entitlement and a matching profile
    trace( "push registration failed: " + message );
}
2 · 앱 실행 중 알림
Incoming.as
function onNotification( json:String ):void
{
    // the full payload as your server sent it: the "aps" part plus your own keys
    var payload:Object = JSON.parse( json );
    if ( payload.hasOwnProperty( "stationId" ) )     // a key your server adds
        openLiveView( payload.stationId );           // your app function
}

// later, e.g. after the user signed in to another account
function onLogin():void
{
    if ( push.token != null )        // the last token; null until registration finished
        sendTokenToServer( push.token );
}
3 · 권한 상태와 시스템 설정
Settings.as
import flash.events.Event;
import flash.desktop.NativeApplication;

// the live status arrives asynchronously; the callback stays set and
// also receives the answer when register() shows the prompt
push.refreshStatus( updateNotificationSwitch );

function updateNotificationSwitch( status:int ):void
{
    if ( status == Push.STATUS_AUTHORIZED )         showSwitch( "on" );    // your app function
    else if ( status == Push.STATUS_DENIED )         showSwitch( "off" );
    else if ( status == Push.STATUS_NOT_DETERMINED ) showSwitch( "not asked" );
}

// macOS never asks a second time: the way back is System Settings
function onSwitchTapped():void
{
    if ( push.authStatus == Push.STATUS_DENIED ) push.openSettings();
}

// the user may have changed it there: read it again when the app comes back
NativeApplication.nativeApplication.addEventListener( Event.ACTIVATE, function( e:Event ):void {
    push.refreshStatus( updateNotificationSwitch );
});
4 · 콜백 대신 이벤트로 수신
Events.as
import flash.events.StatusEvent;

push.addEventListener( StatusEvent.STATUS, function( e:StatusEvent ):void {
    // here the LEVEL names the kind and the CODE carries the value
    if ( e.level == Push.TOKEN )             sendTokenToServer( e.code );
    else if ( e.level == Push.ERROR )        trace( "push error: " + e.code );
    else if ( e.level == Push.NOTIFICATION ) onNotification( e.code );   // JSON
});

push.register();   // all three callbacks are optional

API 개요

Push.getInstance()단일 인스턴스를 반환합니다.
isSupportedmacOS에서는 true, 그 외에는 false입니다.
register(onToken, onError, onNotification)권한을 요청하고 원격 알림에 등록합니다. 세 콜백은 모두 선택 사항이며, onNotification은 앱이 실행 중일 때 호출됩니다. 푸시를 지원하지 않는 곳에서는 false를 반환합니다.
token마지막 기기 토큰이며, 등록이 끝나기 전까지는 null입니다.
authStatus마지막으로 알려진 권한 상태이며, register() 또는 refreshStatus()가 실행되기 전에는 -1입니다.
refreshStatus(onStatus)현재 권한 상태를 읽습니다. 상태가 확인되면 onStatus(status:int)가 호출되며, register()의 권한 요청에 대한 응답이 오면 다시 호출됩니다.
openSettings()시스템 설정의 알림 페이지를 엽니다.
STATUS_NOT_DETERMINED, STATUS_DENIED, STATUS_AUTHORIZED권한 상태 값 0, 1, 2. macOS는 3(provisional)과 4(ephemeral)도 보고할 수 있습니다.
TOKEN, ERROR, NOTIFICATION리스너용 StatusEvent 레벨: 레벨 이름은 종류를, code는 값을 나타냅니다.

이벤트

level tokencode = 기기 토큰, 16진수 문자열
level errorcode = 등록 시 발생한 오류 메시지
level notificationcode = JSON 형식의 알림 페이로드

KlugPush 구매

AIR 애플리케이션 1개에 대한 연간 라이선스이며 12개월간 모든 업데이트를 제공합니다. 결제 후 확장, ActionScript 라이브러리, 문서를 이메일로 보내 드리며, 보통 영업일 기준 1일 이내입니다. 라이선스 및 약관

심플
€19 / 년
  • AIR 애플리케이션 1개에 대한 라이선스
  • 12개월간 모든 업데이트
  • 지원 없음
심플 구매
스탠더드
€149 / 년
  • AIR 애플리케이션 1개에 대한 라이선스
  • 12개월간 모든 업데이트
  • 7일 이내 이메일 답변
스탠더드 구매
프라이어리티
€299 / 년
  • AIR 애플리케이션 1개에 대한 라이선스
  • 12개월간 모든 업데이트
  • 48시간 이내 이메일 답변
프라이어리티 구매
세금은 Link(Stripe)가 결제 시 계산합니다. 결제 중에 AIR 앱의 애플리케이션 ID를 입력합니다.

요구 사항

AIR SDK51.x (HARMAN)
macOSmacOS 11 이상
서명푸시 알림 entitlement와 일치하는 프로비저닝 프로파일
서버Apple의 푸시 서비스를 통해 알림 전송