Files
2nd/10_Wiki/Topics/Domain_Programming/Coding/iOS_Push_Notifications.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

4.5 KiB

id, title, category, status, source_trust_level, verification_status, created_at, updated_at, tags, tech_stack, applied_in, aliases
id title category status source_trust_level verification_status created_at updated_at tags tech_stack applied_in aliases
ios-push-notifications iOS Push Notifications — APNs / 권한 / 백그라운드 Coding draft B conceptual 2026-05-09 2026-05-09
ios
push
apns
notifications
vibe-coding
language applicable_to
Swift / APNs
iOS
APNs
device token
silent push
rich notification

iOS Push Notifications

Apple Push Notification service (APNs) 통한 push. (1) 권한 요청, (2) device token 받기 → 서버 등록, (3) APNs payload, (4) 받은 후 처리 4단계. silent push 와 alert push 다름.

📖 핵심 개념

  • Alert push: UI 표시 (사용자 권한 필요).
  • Silent push: 백그라운드 데이터 sync — UI 없음, 권한 X. content-available: 1.
  • 사용자 행동 (탭, action) 처리 별도.

💻 코드 패턴

권한 요청

import UserNotifications

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound, .provisional]) { granted, error in
    if granted {
        DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() }
    }
}

provisional: 사용자 명시 동의 없이 silently 등록 → 알림이 처음엔 조용히 노티 센터에만. 좋은 UX.

Device token 받기 (AppDelegate)

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
    Task { try? await api.registerPushToken(token) }
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("APNs reg failed: \(error)")
}

Foreground / background 표시

// AppDelegate / scene
UNUserNotificationCenter.current().delegate = self

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            willPresent notification: UNNotification,
                            withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler([.banner, .badge, .sound]) // foreground 에서도 banner
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    if let url = userInfo["deeplink"] as? String { open(url) }
    completionHandler()
}

Silent push 처리 (background fetch)

func application(_ application: UIApplication,
                 didReceiveRemoteNotification userInfo: [AnyHashable : Any]) async -> UIBackgroundFetchResult {
    do {
        try await syncManager.pull()
        return .newData
    } catch {
        return .failed
    }
}

Info.plist → Background Modes → Remote notifications enable.

APNs payload 예시

{
  "aps": {
    "alert": { "title": "새 메시지", "body": "Alice: 안녕" },
    "badge": 3,
    "sound": "default",
    "thread-id": "chat-1",
    "category": "MESSAGE"
  },
  "deeplink": "myapp://chat/1"
}

Silent:

{ "aps": { "content-available": 1 }, "syncToken": "abc" }

🤔 의사결정 기준

알림 종류 사용
사용자 메시지 (chat, mention) Alert (소리 + 진동)
백그라운드 sync (이메일, 캘린더) Silent (content-available)
부드러운 안내 (cron 마케팅) Provisional (조용한 노티)
시간 민감 (alarm, 결제 인증) Time-Sensitive interrupt level
위치 변화 / 트리거 Location notification

안티패턴

  • 권한 요청을 앱 첫 실행에 즉시: 거부율 높음. 가치 보여준 후 적절 시점.
  • device token 한 번만 등록: token 은 변경 가능 (앱 재설치, OS 업그레이드). 매 launch 등록 + 서버 dedup.
  • token 을 분석/로그에 남김: PII 비슷. redact.
  • silent push 폭주: APNs 가 throttle. 10/hour 정도가 안전.
  • 백그라운드 fetch 가 너무 무거움: 30초 한도. 가벼운 작업만, 큰 sync 는 BGTask.
  • iOS Foreground 에서 알림 안 보여줌 가정: willPresent 안 구현하면 그냥 사라짐.
  • notification action 안 처리: 사용자 답장 / 액션 버튼 무반응.

🤖 LLM 활용 힌트

  • 권한 = provisional 우선, 명시 권한은 가치 노출 후.
  • Silent 는 조심 (throttle).

🔗 관련 문서