Skip to content

Commit 9b1bd93

Browse files
authored
Merge pull request #556 from firebase/feature/tvos-messaging-support
Feature/tvos messaging support
2 parents 80513fb + 4768a77 commit 9b1bd93

File tree

7 files changed

+399
-26
lines changed

7 files changed

+399
-26
lines changed

messaging/integration_test/Podfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11

22
source 'https://github.com/CocoaPods/Specs.git'
3-
platform :ios, '10.0'
43
# Firebase Cloud Messaging test application.
54

65
target 'integration_test' do
6+
platform :ios, '10.0'
7+
pod 'Firebase/Messaging', '8.3.0'
8+
end
9+
10+
target 'integration_test_tvos' do
11+
platform :tvos, '10.0'
712
pod 'Firebase/Messaging', '8.3.0'
813
end
914

messaging/integration_test/integration_test.xcodeproj/project.pbxproj

Lines changed: 300 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder.AppleTV.Storyboard" version="3.0" toolsVersion="13122.16" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="tne-QT-ifu">
11+
<objects>
12+
<viewController id="BYZ-38-t0r" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
14+
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
17+
<viewLayoutGuide key="safeArea" id="wu6-TO-1qx"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
21+
</objects>
22+
</scene>
23+
</scenes>
24+
</document>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder.AppleTV.Storyboard" version="3.0" toolsVersion="13122.16" targetRuntime="AppleTV" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="tne-QT-ifu">
11+
<objects>
12+
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
13+
<layoutGuides>
14+
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
15+
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
16+
</layoutGuides>
17+
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
18+
<rect key="frame" x="0.0" y="0.0" width="1920" height="1080"/>
19+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20+
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
21+
<viewLayoutGuide key="safeArea" id="wu6-TO-1qx"/>
22+
</view>
23+
</viewController>
24+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
25+
</objects>
26+
</scene>
27+
</scenes>
28+
</document>

messaging/src/ios/messaging.mm

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,42 @@ void NotifyListenerSet(Listener* listener) {
196196
LogInfo("FCM: Using FCM senderID %s", senderID.UTF8String);
197197
id appDelegate = [UIApplication sharedApplication];
198198

199-
#if FIREBASE_PLATFORM_IOS
200-
// Register for remote notifications. Both codepaths result in
201-
// application:didRegisterForRemoteNotificationsWithDeviceToken: being called when they
202-
// complete, or application:didFailToRegisterForRemoteNotificationsWithError: if there was an
203-
// error. We complete the future there.
204-
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
205-
// iOS 7.1 or earlier
206-
UIRemoteNotificationType allNotificationTypes =
207-
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert |
208-
UIRemoteNotificationTypeBadge);
209-
[appDelegate registerForRemoteNotificationTypes:allNotificationTypes];
210-
} else {
211-
// iOS 8 or later
212-
UIUserNotificationType allNotificationTypes =
213-
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
214-
UIUserNotificationSettings *settings =
215-
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
216-
[appDelegate registerUserNotificationSettings:settings];
199+
#if FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
200+
if ([UNUserNotificationCenter class] != nil) {
201+
// iOS 10 or later, and tvOS
202+
// For iOS 10 display notification (sent via APNS)
203+
[UNUserNotificationCenter currentNotificationCenter].delegate = appDelegate;
204+
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
205+
UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
206+
[[UNUserNotificationCenter currentNotificationCenter]
207+
requestAuthorizationWithOptions:authOptions
208+
completionHandler:^(BOOL granted, NSError * _Nullable error) {
209+
}];
217210
[appDelegate registerForRemoteNotifications];
218211
}
212+
#endif //FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_TVOS
213+
214+
#if FIREBASE_PLATFORM_IOS
215+
// Register for remote notifications. Both codepaths result in
216+
// application:didRegisterForRemoteNotificationsWithDeviceToken: being called when they
217+
// complete, or application:didFailToRegisterForRemoteNotificationsWithError: if there was an
218+
// error. We complete the future there.
219+
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
220+
// iOS 7.1 or earlier
221+
UIRemoteNotificationType allNotificationTypes =
222+
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert |
223+
UIRemoteNotificationTypeBadge);
224+
[appDelegate registerForRemoteNotificationTypes:allNotificationTypes];
225+
} else if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_4) {
226+
// 8.0 <= iOS version <= 9.4
227+
// >= 10.0 is handled by the first if block above.
228+
UIUserNotificationType allNotificationTypes =
229+
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
230+
UIUserNotificationSettings *settings =
231+
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
232+
[appDelegate registerUserNotificationSettings:settings];
233+
[appDelegate registerForRemoteNotifications];
234+
}
219235
#endif // FIREBASE_PLATFORM_IOS
220236

221237
// Only request the token automatically if permitted
@@ -524,11 +540,13 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
524540
[user_notification_center setDelegate:(id<UNUserNotificationCenterDelegate>)application];
525541
}
526542

543+
g_message_notification_opened = false;
527544
#if FIREBASE_PLATFORM_IOS
528545
// If the app was launched with a notification, cache it until we're connected.
529546
g_launch_notification =
530547
[launch_options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
531548
g_message_notification_opened = g_launch_notification != nil;
549+
#endif // FIREBASE_PLATFORM_IOS
532550

533551
IMP app_delegate_application_did_finish_launching_with_options =
534552
SwizzledMethodCache().GetMethodForObject(
@@ -551,7 +569,6 @@ static BOOL AppDelegateApplicationDidFinishLaunchingWithOptions(id self, SEL sel
551569
[invocation getReturnValue:&ret];
552570
return ret;
553571
}
554-
#endif // FIREBASE_PLATFORM_IOS
555572
return NO;
556573
}
557574

scripts/gha/build_ios_tvos.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@
6565
},
6666

6767
'tvos': {
68-
'supported_targets' : ('firebase_analytics', 'firebase_auth',
69-
'firebase_database', 'firebase_firestore',
70-
'firebase_functions', 'firebase_installations',
71-
'firebase_messaging', 'firebase_remote_config',
72-
'firebase_storage'),
68+
'supported_targets' : ('firebase_auth', 'firebase_database',
69+
'firebase_firestore', 'firebase_functions',
70+
'firebase_installations', 'firebase_messaging',
71+
'firebase_remote_config', 'firebase_storage'),
7372
'device': {
7473
'architectures' : ('arm64',),
7574
'toolchain' : 'cmake/toolchains/apple.toolchain.cmake',

scripts/gha/integration_testing/build_testapps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"full_name": "FirebaseMessaging",
112112
"bundle_id": "com.google.FirebaseCppMessagingTestApp.dev",
113113
"ios_target": "integration_test",
114-
"tvos_target": "",
114+
"tvos_target": "integration_test_tvos",
115115
"testapp_path": "messaging/integration_test",
116116
"frameworks": [
117117
"firebase_messaging.xcframework",

0 commit comments

Comments
 (0)