feeddo_push_notification_apns 0.1.3
feeddo_push_notification_apns: ^0.1.3 copied to clipboard
Direct Apple Push Notification service (APNs) bridge for Flutter on iOS. Lightweight APNs token management, foreground presentation, and tap handling without Firebase.
feeddo_push_notification_apns #
A lightweight, zero-boilerplate Apple Push Notification service (APNs) bridge for Flutter iOS applications.
Designed specifically for apps using Feeddo or any iOS-only Flutter app that needs direct APNs push notifications without requiring Firebase or FCM.
โจ Why feeddo_push_notification_apns? #
- ๐ซ No Firebase / FCM Required: Communicates directly with Apple APNs.
- โก Zero Swift Boilerplate in
AppDelegate: Automatically registers as a Flutter application delegate andUNUserNotificationCenterDelegateโno manual MethodChannel setup or 200 lines of Swift in your project! - ๐ Automatic Token Generation: Translates native binary device tokens to clean hex strings ready for APNs HTTP/2 servers.
- ๐ฑ Cold-Start & Background Tap Handling: Reliably delivers initial notifications when launched from terminated or background states.
- ๐ Foreground Banners: Automatically displays banners, sounds, and badges when notifications arrive while the app is active, and notifies Flutter via streams.
- ๐ค First-Class Feeddo Integration: Provides
attachToFeeddoto seamlessly wire push token sync and notification routing tofeeddo_flutter.
๐ Getting Started #
1. Add to pubspec.yaml #
flutter pub add feeddo_push_notification_apns
2. Configure iOS Capabilities #
In Xcode:
- Open your
ios/Runner.xcworkspace. - Select the
Runnertarget โ Signing & Capabilities โ + Capability โ Add Push Notifications. - Under Background Modes (if desired), check Remote notifications.
(Or ensure Runner.entitlements contains the aps-environment key:)
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
Note: Debug builds and the iOS Simulator use
development. Release and TestFlight builds are automatically signed withproductionby Xcode.
๐ Usage with Feeddo #
import 'package:flutter/material.dart';
import 'package:feeddo_flutter/feeddo_flutter.dart';
import 'package:feeddo_push_notification_apns/feeddo_push_notification_apns.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 1. Initialize APNs Bridge (registers delegates and retrieves initial launch tokens)
await FeeddoPushNotificationApns.instance.initialize();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
FeeddoApnsSubscription? _apnsSub;
@override
void initState() {
super.initState();
_initFeeddo();
}
Future<void> _initFeeddo() async {
// Initialize Feeddo SDK
await Feeddo.init(
apiKey: 'YOUR_FEEDDO_API_KEY',
context: context,
externalUserId: 'user_123',
pushToken: FeeddoPushNotificationApns.instance.token,
pushProvider: FeeddoPushProvider.apns,
isInAppNotificationOn: true,
);
// Wire live APNs token updates and notification taps
_apnsSub = FeeddoPushNotificationApns.instance.attachToFeeddo(
onToken: (token) => Feeddo.registerPushToken(
pushToken: token,
pushProvider: FeeddoPushProvider.apns,
),
onNotificationTap: (payload) => Feeddo.handleNotificationTap(
context,
payload,
),
);
}
@override
void dispose() {
_apnsSub?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(body: Center(child: Text('Hello Feeddo'))),
);
}
}
๐ Requesting Notification Permissions in an Appropriate Place #
Do not prompt for notification permissions directly in main() on cold startup. In line with Apple's Human Interface Guidelines, prompt the user in a contextual, appropriate place so they understand why notifications are valuable:
- During Onboarding: On a dedicated permissions or benefits walkthrough screen.
- In Settings / Notifications: With a toggle that user controls.
- In the Feedback / Support Flow: Right when the user taps to open Support Chat or submits a bug report/feature request, so they are alerted when a reply arrives:
// Place this inside Settings, Onboarding, or when the user opens Support:
final granted = await FeeddoPushNotificationApns.instance.requestNotificationPermissions(
alert: true,
badge: true,
sound: true,
);
if (granted) {
debugPrint('Notification permissions granted by user.');
}
๐ก Standalone APNs Usage (Without Feeddo) #
You can also use this library as a general-purpose APNs bridge:
final apns = FeeddoPushNotificationApns.instance;
// Initialize
final result = await apns.initialize();
print('Cached token: ${result.token}');
// Request permission when appropriate in your app flow:
final granted = await apns.requestNotificationPermissions();
// Check detailed notification settings
final settings = await apns.getNotificationSettings();
print('Authorized: ${settings.isAuthorized}, Sound: ${settings.soundEnabled}');
// Listen for device token
apns.onToken.listen((hexToken) {
print('New APNs device token: $hexToken');
});
// Listen for user tapping a notification
apns.onNotificationOpened.listen((Map<String, dynamic> payload) {
print('Notification tapped: $payload');
});
// Listen for foreground notifications
apns.onForegroundNotification.listen((Map<String, dynamic> payload) {
print('Foreground notification: $payload');
});
// Check if app was cold-launched by tapping a push notification
final initialPayload = await apns.getInitialNotification();
if (initialPayload != null) {
print('Cold launch payload: $initialPayload');
}
๐งช Testing on iOS Simulator #
To test push notifications on an Apple Silicon Mac using the iOS Simulator:
- Ensure your Apple ID is signed in under Settings โ Apple ID in the simulator.
- If the simulator does not deliver push notifications, kickstart the push daemon on your Mac:
launchctl kickstart -k system/com.apple.apsd
๐ License #
MIT License. See LICENSE for details.