Skip to content

Commit ad1fea4

Browse files
totoflovilmart
authored andcommitted
tvOS push support (#1375)
* Add PFPush, PFInstallation to tvOS. * Add support for Installation and Push on tvOS via CocoaPods. * containingApplicationBundleIdentifier and applicationGroupIdentifier should also be availible for tvos * Allow badge updates on tvOS * Also return device model on tvOS * Setup project for tvOS * Use @available for tvOS since applicationIconBadgeNumber appeared in tvOS 10 * fix visibility of pfpush * Allow tvOS to have a badge as well * tvos installations need to be identified by tvos because the parse server adapter uses this nomenclature * Use FBSDKErrorDialogUnavailable instead of deprecated code
1 parent 8740d31 commit ad1fea4

28 files changed

+152
-72
lines changed

Parse.podspec

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@ Pod::Spec.new do |s|
3434
'Parse/Parse/Internal/Purchase/**/*.{h,m}',
3535
'Parse/Parse/Internal/PFMemoryEventuallyQueue.{h,m}'
3636
s.tvos.exclude_files = 'Parse/Parse/PFNetworkActivityIndicatorManager.{h,m}',
37-
'Parse/Parse/PFPush.{h,m}',
38-
'Parse/Parse/PFPush+Synchronous.{h,m}',
39-
'Parse/Parse/PFPush+Deprecated.{h,m}',
40-
'Parse/Parse/PFInstallation.{h,m}',
41-
'Parse/Parse/Internal/PFAlertView.{h,m}',
42-
'Parse/Parse/Internal/Push/**/*.{h,m}',
43-
'Parse/Parse/Internal/Installation/Controller/*.{h,m}',
44-
'Parse/Parse/Internal/Installation/Constants/*.{h,m}',
45-
'Parse/Parse/Internal/Installation/CurrentInstallationController/*.{h,m}',
46-
'Parse/Parse/Internal/Installation/PFInstallationPrivate.h',
47-
'Parse/Parse/Internal/Commands/PFRESTPushCommand.{h,m}'
37+
'Parse/Parse/Internal/PFAlertView.{h,m}'
4838
s.watchos.exclude_files = 'Parse/Parse/PFNetworkActivityIndicatorManager.{h,m}',
4939
'Parse/Parse/PFProduct.{h,m}',
5040
'Parse/Parse/PFPurchase.{h,m}',

Parse/Parse.xcodeproj/project.pbxproj

Lines changed: 92 additions & 4 deletions
Large diffs are not rendered by default.

Parse/Parse/Internal/Commands/PFRESTPushCommand.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212
#import <Parse/PFConstants.h>
1313

14-
PF_TV_UNAVAILABLE_WARNING
1514
PF_WATCH_UNAVAILABLE_WARNING
1615

1716
@class PFPushState;
1817

1918
NS_ASSUME_NONNULL_BEGIN
2019

21-
PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE @interface PFRESTPushCommand : PFRESTCommand
20+
PF_WATCH_UNAVAILABLE @interface PFRESTPushCommand : PFRESTCommand
2221

2322
+ (nullable instancetype)sendPushCommandWithPushState:(PFPushState *)state
2423
sessionToken:(nullable NSString *)sessionToken

Parse/Parse/Internal/Installation/Controller/PFInstallationController.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
#import "PFCoreDataProvider.h"
1313
#import "PFObjectControlling.h"
1414

15-
PF_TV_UNAVAILABLE_WARNING
1615
PF_WATCH_UNAVAILABLE_WARNING
1716

1817
NS_ASSUME_NONNULL_BEGIN
1918

20-
PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE @interface PFInstallationController : NSObject <PFObjectControlling>
19+
PF_WATCH_UNAVAILABLE @interface PFInstallationController : NSObject <PFObjectControlling>
2120

2221
@property (nonatomic, weak, readonly) id<PFObjectControllerProvider, PFCurrentInstallationControllerProvider> dataSource;
2322

Parse/Parse/Internal/Installation/CurrentInstallationController/PFCurrentInstallationController.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#import "PFDataProvider.h"
1717
#import "PFMacros.h"
1818

19-
PF_TV_UNAVAILABLE_WARNING
2019
PF_WATCH_UNAVAILABLE_WARNING
2120

2221
extern NSString *const PFCurrentInstallationFileName;
@@ -25,7 +24,7 @@ extern NSString *const PFCurrentInstallationPinName;
2524
@class BFTask<__covariant BFGenericType>;
2625
@class PFInstallation;
2726

28-
PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE @interface PFCurrentInstallationController : NSObject <PFCurrentObjectControlling>
27+
PF_WATCH_UNAVAILABLE @interface PFCurrentInstallationController : NSObject <PFCurrentObjectControlling>
2928

3029
@property (nonatomic, weak, readonly) id<PFInstallationIdentifierStoreProvider> commonDataSource;
3130
@property (nonatomic, weak, readonly) id<PFObjectFilePersistenceControllerProvider> coreDataSource;

Parse/Parse/Internal/Installation/PFInstallationPrivate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#import <Parse/PFInstallation.h>
1313

14-
PF_TV_UNAVAILABLE_WARNING
1514
PF_WATCH_UNAVAILABLE_WARNING
1615

1716
@interface PFInstallation (Private)

Parse/Parse/Internal/PFApplication.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ + (instancetype)currentApplication {
3737
- (id)init {
3838
self = [super init];
3939
if (self) {
40-
#if TARGET_OS_IOS
41-
[self.systemApplication addObserver:self forKeyPath:@"applicationIconBadgeNumber" options:NSKeyValueObservingOptionNew context:nil];
42-
_iconBadgeNumber = self.systemApplication.applicationIconBadgeNumber;
40+
#if TARGET_OS_IOS || TARGET_OS_TV
41+
if (@available(iOS 1.0, tvOS 10.0, *)) {
42+
[self.systemApplication addObserver:self forKeyPath:@"applicationIconBadgeNumber" options:NSKeyValueObservingOptionNew context:nil];
43+
_iconBadgeNumber = self.systemApplication.applicationIconBadgeNumber;
44+
}
4345
#endif
4446
}
4547
return self;
@@ -62,9 +64,9 @@ - (BOOL)isExtensionEnvironment {
6264
}
6365

6466
- (NSInteger)iconBadgeNumber {
65-
#if TARGET_OS_WATCH || TARGET_OS_TV
67+
#if TARGET_OS_WATCH
6668
return 0;
67-
#elif TARGET_OS_IOS
69+
#elif TARGET_OS_IOS || TARGET_OS_TV
6870
return _iconBadgeNumber;
6971
#elif PF_TARGET_OS_OSX
7072
// Make sure not to use `NSApp` here, because it doesn't work sometimes,
@@ -88,10 +90,12 @@ - (NSInteger)iconBadgeNumber {
8890

8991
- (void)setIconBadgeNumber:(NSInteger)iconBadgeNumber {
9092
if (self.iconBadgeNumber != iconBadgeNumber) {
91-
#if TARGET_OS_IOS
93+
#if TARGET_OS_IOS || TARGET_OS_TV
9294
_iconBadgeNumber = iconBadgeNumber;
9395
dispatch_block_t block = ^{
94-
self.systemApplication.applicationIconBadgeNumber = iconBadgeNumber;
96+
if (@available(iOS 1.0, tvOS 10.0, *)) {
97+
self.systemApplication.applicationIconBadgeNumber = iconBadgeNumber;
98+
}
9599
};
96100
if ([NSThread currentThread].isMainThread) {
97101
block();
@@ -104,7 +108,7 @@ - (void)setIconBadgeNumber:(NSInteger)iconBadgeNumber {
104108
}
105109
}
106110

107-
#if TARGET_OS_IOS
111+
#if TARGET_OS_IOS || TARGET_OS_TV
108112
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
109113
if ([keyPath isEqualToString:@"applicationIconBadgeNumber"] && change) {
110114
_iconBadgeNumber = [change[@"new"] integerValue];
@@ -122,8 +126,10 @@ - (UIApplication *)systemApplication {
122126
}
123127

124128
- (void)dealloc {
125-
#if TARGET_OS_IOS
126-
[self.systemApplication removeObserver:self forKeyPath:@"applicationIconBadgeNumber"];
129+
#if TARGET_OS_IOS || TARGET_OS_TV
130+
if (@available(iOS 1.0, tvOS 10.0, *)) {
131+
[self.systemApplication removeObserver:self forKeyPath:@"applicationIconBadgeNumber"];
132+
}
127133
#endif
128134
}
129135

Parse/Parse/Internal/PFCoreManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PFObjectFilePersistenceControllerProvider,
4848
PFPinningObjectStoreProvider,
4949
PFObjectLocalIdStoreProvider,
5050
PFUserAuthenticationControllerProvider,
51-
#if !TARGET_OS_TV && !TARGET_OS_WATCH
51+
#if !TARGET_OS_WATCH
5252
PFInstallationControllerProvider,
5353
PFCurrentInstallationControllerProvider,
5454
#endif

Parse/Parse/Internal/PFCoreManager.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#import "PFUserAuthenticationController.h"
3131
#import "PFUserController.h"
3232

33-
#if !TARGET_OS_WATCH && !TARGET_OS_TV
33+
#if !TARGET_OS_WATCH
3434
#import "PFCurrentInstallationController.h"
3535
#import "PFInstallationController.h"
3636
#endif
@@ -63,7 +63,7 @@ @implementation PFCoreManager
6363
@synthesize currentUserController = _currentUserController;
6464
@synthesize userController = _userController;
6565

66-
#if !TARGET_OS_WATCH && !TARGET_OS_TV
66+
#if !TARGET_OS_WATCH
6767
@synthesize currentInstallationController = _currentInstallationController;
6868
@synthesize installationController = _installationController;
6969
#endif
@@ -380,7 +380,7 @@ - (void)setSessionController:(PFSessionController *)sessionController {
380380
});
381381
}
382382

383-
#if !TARGET_OS_WATCH && !TARGET_OS_TV
383+
#if !TARGET_OS_WATCH
384384

385385
///--------------------------------------
386386
#pragma mark - Current Installation Controller
@@ -438,7 +438,7 @@ - (void)setCurrentUserController:(PFCurrentUserController *)currentUserControlle
438438
});
439439
}
440440

441-
#if !TARGET_OS_WATCH && !TARGET_OS_TV
441+
#if !TARGET_OS_WATCH
442442

443443
///--------------------------------------
444444
#pragma mark - Installation Controller

Parse/Parse/Internal/PFDevice.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ - (NSString *)detailedModel {
7777
if (!name) {
7878
#if TARGET_OS_WATCH
7979
name = [WKInterfaceDevice currentDevice].model;
80-
#elif TARGET_OS_IOS
80+
#elif TARGET_OS_IOS || TARGET_OS_TV
8181
name = [UIDevice currentDevice].model;
8282
#elif TARGET_OS_MAC
8383
name = @"Mac";

0 commit comments

Comments
 (0)