Skip to content

Commit 670d7ec

Browse files
committed
Merge pull request #109 from ParsePlatform/nlutsenko.extensions
Make sure we compile for App Extensions from source.
2 parents b9d0efd + 4c269ef commit 670d7ec

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

Parse/Internal/PFAlertView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
#import <Foundation/Foundation.h>
1011
#import <UIKit/UIKit.h>
1112

1213
typedef void(^PFAlertViewCompletion)(NSUInteger selectedOtherButtonIndex);
@@ -17,6 +18,6 @@ typedef void(^PFAlertViewCompletion)(NSUInteger selectedOtherButtonIndex);
1718
message:(NSString *)message
1819
cancelButtonTitle:(NSString *)cancelButtonTitle
1920
otherButtonTitles:(NSArray *)otherButtonTitles
20-
completion:(PFAlertViewCompletion)completion;
21+
completion:(PFAlertViewCompletion)completion NS_EXTENSION_UNAVAILABLE_IOS("");
2122

2223
@end

Parse/Internal/PFApplication.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@
99

1010
#import <Foundation/Foundation.h>
1111

12+
#if TARGET_OS_IPHONE
13+
#import <UIKit/UIKit.h>
14+
#else
15+
#import <AppKit/AppKit.h>
16+
@compatibility_alias UIApplication NSApplication;
17+
#endif
18+
1219
/*!
1320
`PFApplication` class provides a centralized way to get the information about the current application,
1421
or the environment it's running in. Please note, that all device specific things - should go to <PFDevice>.
1522
*/
1623
@interface PFApplication : NSObject
1724

25+
@property (nonatomic, strong, readonly) UIApplication *systemApplication;
26+
1827
@property (nonatomic, assign, readonly, getter=isAppStoreEnvironment) BOOL appStoreEnvironment;
1928
@property (nonatomic, assign, readonly, getter=isExtensionEnvironment) BOOL extensionEnvironment;
2029

Parse/Internal/PFApplication.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ - (BOOL)isExtensionEnvironment {
4848

4949
- (NSInteger)iconBadgeNumber {
5050
#if TARGET_OS_IPHONE
51-
return [UIApplication sharedApplication].applicationIconBadgeNumber;
51+
return self.systemApplication.applicationIconBadgeNumber;
5252
#else
5353
// Make sure not to use `NSApp` here, because it doesn't work sometimes,
5454
// `NSApplication +sharedApplication` does though.
@@ -72,11 +72,16 @@ - (NSInteger)iconBadgeNumber {
7272
- (void)setIconBadgeNumber:(NSInteger)iconBadgeNumber {
7373
if (self.iconBadgeNumber != iconBadgeNumber) {
7474
#if TARGET_OS_IPHONE
75-
[UIApplication sharedApplication].applicationIconBadgeNumber = iconBadgeNumber;
75+
self.systemApplication.applicationIconBadgeNumber = iconBadgeNumber;
7676
#else
7777
[[NSApplication sharedApplication] dockTile].badgeLabel = [@(iconBadgeNumber) stringValue];
7878
#endif
7979
}
8080
}
8181

82+
- (UIApplication *)systemApplication {
83+
// Workaround to make `sharedApplication` still be called even if compiling for App Extensions or WatchKit apps.
84+
return [UIApplication performSelector:@selector(sharedApplication)];
85+
}
86+
8287
@end

Parse/Internal/PFLocationManager.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313

1414
#import "PFConstants.h"
1515
#import "PFGeoPoint.h"
16-
17-
#if !TARGET_OS_IPHONE
18-
19-
// To let us compile for OSX.
20-
@compatibility_alias UIApplication NSApplication;
21-
22-
#endif
16+
#import "PFApplication.h"
2317

2418
@interface PFLocationManager () <CLLocationManagerDelegate>
2519

@@ -66,7 +60,7 @@ - (instancetype)init {
6660

6761
- (instancetype)initWithSystemLocationManager:(CLLocationManager *)manager {
6862
return [self initWithSystemLocationManager:manager
69-
application:[UIApplication sharedApplication]
63+
application:[PFApplication currentApplication].systemApplication
7064
bundle:[NSBundle mainBundle]];
7165
}
7266

Parse/Internal/Push/PFPushPrivate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
2424

2525
#if TARGET_OS_IPHONE
2626

27-
+ (void)showAlertViewWithTitle:(nullable NSString *)title message:(nullable NSString *)message;
27+
+ (void)showAlertViewWithTitle:(nullable NSString *)title message:(nullable NSString *)message NS_EXTENSION_UNAVAILABLE_IOS("");
2828
+ (void)playVibrate;
2929
+ (void)playAudioWithName:(nullable NSString *)audioName;
3030

Parse/PFNetworkActivityIndicatorManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ - (void)_updateNetworkActivityIndicatorVisibilityAfterDelay {
142142
}
143143
}
144144

145-
- (void)_updateNetworkActivityIndicatorVisibility {
145+
- (void)_updateNetworkActivityIndicatorVisibility NS_EXTENSION_UNAVAILABLE_IOS("") {
146146
if (![PFApplication currentApplication].extensionEnvironment) {
147147
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:self.networkActivityIndicatorVisible];
148148
}

Parse/PFPush.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ PF_ASSUME_NONNULL_BEGIN
386386
387387
@param userInfo The userInfo dictionary you get in `appplication:didReceiveRemoteNotification:`.
388388
*/
389-
+ (void)handlePush:(PF_NULLABLE NSDictionary *)userInfo NS_AVAILABLE_IOS(3_0);
389+
+ (void)handlePush:(PF_NULLABLE NSDictionary *)userInfo NS_AVAILABLE_IOS(3_0) PF_EXTENSION_UNAVAILABLE("");
390390

391391
///--------------------------------------
392392
/// @name Managing Channel Subscriptions

0 commit comments

Comments
 (0)