Skip to content

Commit

Permalink
feat(apple): build framework for tvos, watchos (+ simulators), macOS
Browse files Browse the repository at this point in the history
these framework artifacts are untested but do in general seem in harmony with
the tvOS and watchOS and macOS platforms after the #if/#endif precompiler removal of areas
those OSs don't support (tvOS just appears to show a badge and allow data payloads
and that's it, for instance, watchOS doesn't have settings)

macOS desktop target in particular has a similar "deep" framework archive directory structure
(with 'Versions/Current' etc) and even worse it won't actually install in to the archive directory.
But because of that if we specify a derived data path then do our own copy operation we may flatten
the directory structure as part of the archive, and xcodebuild accepts the output when it makes
the xcframework
  • Loading branch information
mikehardy committed Jan 7, 2021
1 parent 09096fa commit 9eb3095
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ ios/Pods
ios/Podfile.lock
ios/NotifeeCore.framework
ios/NotifeeCore.xcworkspace

ios/build

### Flutter ###
# Flutter/Dart/Pub related
Expand Down Expand Up @@ -616,4 +616,4 @@ flutter_export_environment.sh


#tests_react_native
/tests_react_native/playgrounds
/tests_react_native/playgrounds
4 changes: 2 additions & 2 deletions ios/NotifeeCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
PRODUCT_BUNDLE_IDENTIFIER = app.notifee.core.NotifeeCore;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,3,4,6";
};
name = Debug;
};
Expand All @@ -428,7 +428,7 @@
PRODUCT_BUNDLE_IDENTIFIER = app.notifee.core.NotifeeCore;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,3,4,6";
};
name = Release;
};
Expand Down
25 changes: 24 additions & 1 deletion ios/NotifeeCore/NotifeeCore+NSNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
// Copyright © 2020 Invertase. All rights reserved.
//

#import <UIKit/UIKit.h>
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE
@import UIKit;
#else
@import AppKit;
#endif

#import "Private/NotifeeCore+NSNotificationCenter.h"
#import "Private/NotifeeCore+UNUserNotificationCenter.h"

Expand All @@ -27,17 +33,34 @@ - (void)observe {
NotifeeCoreNSNotificationCenter *strongSelf = weakSelf;
// Application
// ObjC -> Initialize other delegates & observers
#if TARGET_OS_IPHONE
#if !TARGET_OS_WATCH
[[NSNotificationCenter defaultCenter]
addObserver:strongSelf
selector:@selector(application_onDidFinishLaunchingNotification:)
name:UIApplicationDidFinishLaunchingNotification
object:nil];
#endif
[[NSNotificationCenter defaultCenter]
addObserver:strongSelf
selector:@selector(messaging_didReceiveRemoteNotification:)
name:@"RNFBMessagingDidReceiveRemoteNotification"
object:nil];
});
#endif
#if !TARGET_OS_IPHONE
[[NSNotificationCenter defaultCenter]
addObserver:strongSelf
selector:@selector(application_onDidFinishLaunchingNotification:)
name:NSApplicationDidFinishLaunchingNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:strongSelf
selector:@selector(messaging_didReceiveRemoteNotification:)
name:@"RNFBMessagingDidReceiveRemoteNotification"
object:nil];
});
#endif
}

// start observing immediately on class load - specifically for
Expand Down
32 changes: 27 additions & 5 deletions ios/NotifeeCore/NotifeeCore+UNUserNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:
(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSDictionary *notifeeNotification =
notification.request.content.userInfo[kNotifeeUserInfoNotification];
NSDictionary *notifeeNotification = nil;
#if !TARGET_OS_TV
notifeeNotification = notification.request.content.userInfo[kNotifeeUserInfoNotification];
#endif

// we only care about notifications created through notifee
if (notifeeNotification != nil) {
Expand All @@ -92,10 +94,22 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
}

if (alert) {
presentationOptions |= UNNotificationPresentationOptionAlert;
if (@available(ios 14, macOS 11, macCatalyst 14, tvOS 14, watchOS 7, *)) {
presentationOptions |= UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner;
} else {
// Guarding with '@available' does not remove deprecation warning unfortunately. Pragma it is
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
presentationOptions |= UNNotificationPresentationOptionAlert;
#pragma clang diagnostic pop
}
}

NSDictionary *notifeeTrigger = notification.request.content.userInfo[kNotifeeUserInfoTrigger];
NSDictionary *notifeeTrigger = nil;
#if !TARGET_OS_TV
notifeeTrigger = notification.request.content.userInfo[kNotifeeUserInfoTrigger];
#endif

if (notifeeTrigger != nil) {
// post DELIVERED event
[[NotifeeCoreDelegateHolder instance] didReceiveNotifeeCoreEvent:@{
Expand All @@ -118,6 +132,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
// The method will be called when the user responded to the notification by opening the application,
// dismissing the notification or choosing a UNNotificationAction. The delegate must be set before
// the application returns from application:didFinishLaunchingWithOptions:.
#if !TARGET_OS_TV
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
Expand Down Expand Up @@ -188,12 +203,19 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
withCompletionHandler:completionHandler];
}
}
#endif

#if !TARGET_OS_TV && !TARGET_OS_WATCH
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
openSettingsForNotification:(nullable UNNotification *)notification {
if (_originalDelegate != nil && originalUNCDelegateRespondsTo.openSettingsForNotification) {
[_originalDelegate userNotificationCenter:center openSettingsForNotification:notification];
if (@available(iOS 12.0, macOS 10.14, macCatalyst 13, *)) {
[_originalDelegate userNotificationCenter:center openSettingsForNotification:notification];
} else {
// Fallback on earlier versions
}
}
}
#endif

@end
Loading

0 comments on commit 9eb3095

Please sign in to comment.