Skip to content
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

feat(apple): build framework for tvos and watchos (+ sims) #56

Closed
wants to merge 2 commits into from
Closed
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
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";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's tvOS (3), watchOS (4), and macOS (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>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brings in 'TARGET_OS_IPHONE' which is a misnomer. That symbol means "Everything except mac Desktop via AppKit (i.e., not via UIKit aka Catalyst)" so is the easiest discriminator to say "am I the pure desktop macos native build?"

#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