Skip to content

Update PFApplication to compile for watchOS. #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Parse/Internal/PFApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

#import <Foundation/Foundation.h>

#if TARGET_OS_IPHONE
#import <Parse/PFConstants.h>

#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#else
#elif TARGET_OS_WATCH
@class UIApplication;
#elif TARGET_OS_MAC
#import <AppKit/AppKit.h>
@compatibility_alias UIApplication NSApplication;
#endif
Expand Down
18 changes: 12 additions & 6 deletions Parse/Internal/PFApplication.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#import "PFApplication.h"

#if TARGET_OS_IPHONE
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#else
#elif !TARGET_OS_WATCH && TARGET_OS_MAC
#import <AppKit/AppKit.h>
#endif

Expand Down Expand Up @@ -47,9 +47,11 @@ - (BOOL)isExtensionEnvironment {
}

- (NSInteger)iconBadgeNumber {
#if TARGET_OS_IPHONE
#if TARGET_OS_WATCH
return 0;
#elif TARGET_OS_IOS
return self.systemApplication.applicationIconBadgeNumber;
#else
#elif TARGET_OS_MAC
// Make sure not to use `NSApp` here, because it doesn't work sometimes,
// `NSApplication +sharedApplication` does though.
NSString *badgeLabel = [[NSApplication sharedApplication] dockTile].badgeLabel;
Expand All @@ -71,17 +73,21 @@ - (NSInteger)iconBadgeNumber {

- (void)setIconBadgeNumber:(NSInteger)iconBadgeNumber {
if (self.iconBadgeNumber != iconBadgeNumber) {
#if TARGET_OS_IPHONE
#if TARGET_OS_IOS
self.systemApplication.applicationIconBadgeNumber = iconBadgeNumber;
#else
#elif !TARGET_OS_WATCH
[[NSApplication sharedApplication] dockTile].badgeLabel = [@(iconBadgeNumber) stringValue];
#endif
}
}

- (UIApplication *)systemApplication {
#if TARGET_OS_WATCH
return nil;
#else
// Workaround to make `sharedApplication` still be called even if compiling for App Extensions or WatchKit apps.
return [UIApplication performSelector:@selector(sharedApplication)];
#endif
}

@end