-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios):) add notification service extension target for image suppo…
…rt in notifications
- Loading branch information
1 parent
3623a50
commit 95e52ed
Showing
9 changed files
with
433 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const IPHONEOS_DEPLOYMENT_TARGET = '11.0'; | ||
export const TARGETED_DEVICE_FAMILY = `"1,2"`; | ||
|
||
export const NSE_PODFILE_SNIPPET = ` | ||
target 'RNFirebaseNotificationServiceExtension' do | ||
use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] | ||
pod 'GoogleUtilities' | ||
pod 'Firebase/Messaging' | ||
end | ||
`; | ||
|
||
export const NSE_PODFILE_REGEX = /target 'RNFirebaseNotificationServiceExtension'/; | ||
|
||
export const GROUP_IDENTIFIER_TEMPLATE_REGEX = /{{GROUP_IDENTIFIER}}/gm; | ||
export const BUNDLE_SHORT_VERSION_TEMPLATE_REGEX = /{{BUNDLE_SHORT_VERSION}}/gm; | ||
export const BUNDLE_VERSION_TEMPLATE_REGEX = /{{BUNDLE_VERSION}}/gm; | ||
|
||
export const DEFAULT_BUNDLE_VERSION = '1'; | ||
export const DEFAULT_BUNDLE_SHORT_VERSION = '1.0'; | ||
|
||
export const NSE_TARGET_NAME = 'RNFirebaseNotificationServiceExtension'; | ||
export const NSE_SOURCE_FILE = 'NotificationService.m'; | ||
export const NSE_EXT_FILES = [ | ||
'NotificationService.h', | ||
`${NSE_TARGET_NAME}.entitlements`, | ||
`${NSE_TARGET_NAME}-Info.plist`, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as fs from 'fs'; | ||
|
||
export async function readFile(path: string): Promise<string> { | ||
return new Promise<string>((resolve, reject) => { | ||
fs.readFile(path, 'utf8', (err, data) => { | ||
if (err || !data) { | ||
// eslint-disable-next-line no-console | ||
console.error("Couldn't read file:" + path); | ||
reject(err); | ||
return; | ||
} | ||
resolve(data); | ||
}); | ||
}); | ||
} | ||
|
||
export async function writeFile(path: string, contents: string): Promise<void> { | ||
return new Promise<void>((resolve, reject) => { | ||
fs.writeFile(path, contents, 'utf8', err => { | ||
if (err) { | ||
// eslint-disable-next-line no-console | ||
console.error("Couldn't write file:" + path); | ||
reject(err); | ||
return; | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
export async function copyFile(path1: string, path2: string): Promise<void> { | ||
const fileContents = await readFile(path1); | ||
await writeFile(path2, fileContents); | ||
} | ||
|
||
export function dirExists(path: string): boolean { | ||
return fs.existsSync(path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { | ||
withNotificationServiceExtension, | ||
withRNFirebaseXcodeProject, | ||
withAppEnvironment, | ||
withEasManagedCredentials, | ||
} from './setupNotificationServiceExtension'; | ||
|
||
export { | ||
withNotificationServiceExtension, | ||
withRNFirebaseXcodeProject, | ||
withAppEnvironment, | ||
withEasManagedCredentials, | ||
}; |
5 changes: 5 additions & 0 deletions
5
packages/messaging/plugin/src/ios/serviceExtensionFiles/NotificationService.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#import <UserNotifications/UserNotifications.h> | ||
|
||
@interface NotificationService : UNNotificationServiceExtension | ||
|
||
@end |
25 changes: 25 additions & 0 deletions
25
packages/messaging/plugin/src/ios/serviceExtensionFiles/NotificationService.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#import "NotificationService.h" | ||
#import "FirebaseMessaging.h" | ||
|
||
@interface NotificationService () | ||
|
||
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); | ||
@property (nonatomic, strong) UNNotificationRequest *receivedRequest; | ||
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; | ||
|
||
@end | ||
|
||
@implementation NotificationService | ||
|
||
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { | ||
self.contentHandler = contentHandler; | ||
self.bestAttemptContent = [request.content mutableCopy]; | ||
|
||
[[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler]; | ||
} | ||
|
||
- (void)serviceExtensionTimeWillExpire { | ||
self.contentHandler(self.bestAttemptContent); | ||
} | ||
|
||
@end |
31 changes: 31 additions & 0 deletions
31
...ng/plugin/src/ios/serviceExtensionFiles/RNFirebaseNotificationServiceExtension-Info.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>RNFirebaseNotificationServiceExtension</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>{{BUNDLE_SHORT_VERSION}}</string> | ||
<key>CFBundleVersion</key> | ||
<string>{{BUNDLE_VERSION}}</string> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.usernotifications.service</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>NotificationService</string> | ||
</dict> | ||
</dict> | ||
</plist> |
10 changes: 10 additions & 0 deletions
10
.../plugin/src/ios/serviceExtensionFiles/RNFirebaseNotificationServiceExtension.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.application-groups</key> | ||
<array> | ||
<string>{{GROUP_IDENTIFIER}}</string> | ||
</array> | ||
</dict> | ||
</plist> |
Oops, something went wrong.