[notifications][ios] Properly define attachment options
This commit is contained in:
parent
ee3b2932ef
commit
7acace4ce6
@ -463,10 +463,27 @@ RCT_EXPORT_METHOD(setBadge: (NSInteger) number) {
|
|||||||
for (NSDictionary *a in ios[@"attachments"]) {
|
for (NSDictionary *a in ios[@"attachments"]) {
|
||||||
NSString *identifier = a[@"identifier"];
|
NSString *identifier = a[@"identifier"];
|
||||||
NSURL *url = [NSURL URLWithString:a[@"url"]];
|
NSURL *url = [NSURL URLWithString:a[@"url"]];
|
||||||
NSDictionary *options = a[@"options"];
|
NSMutableDictionary *attachmentOptions = nil;
|
||||||
|
|
||||||
|
if (a[@"options"]) {
|
||||||
|
NSDictionary *options = a[@"options"];
|
||||||
|
attachmentOptions = [[NSMutableDictionary alloc] init];
|
||||||
|
|
||||||
|
for (id key in options) {
|
||||||
|
if ([key isEqualToString:@"typeHint"]) {
|
||||||
|
attachmentOptions[UNNotificationAttachmentOptionsTypeHintKey] = options[key];
|
||||||
|
} else if ([key isEqualToString:@"thumbnailHidden"]) {
|
||||||
|
attachmentOptions[UNNotificationAttachmentOptionsThumbnailHiddenKey] = options[key];
|
||||||
|
} else if ([key isEqualToString:@"thumbnailClippingRect"]) {
|
||||||
|
attachmentOptions[UNNotificationAttachmentOptionsThumbnailClippingRectKey] = options[key];
|
||||||
|
} else if ([key isEqualToString:@"thumbnailTime"]) {
|
||||||
|
attachmentOptions[UNNotificationAttachmentOptionsThumbnailTimeKey] = options[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NSError *error;
|
NSError *error;
|
||||||
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:url options:options error:&error];
|
UNNotificationAttachment *attachment = [UNNotificationAttachment attachmentWithIdentifier:identifier URL:url options:attachmentOptions error:&error];
|
||||||
if (attachment) {
|
if (attachment) {
|
||||||
[attachments addObject:attachment];
|
[attachments addObject:attachment];
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,14 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
import type Notification from './Notification';
|
import type Notification from './Notification';
|
||||||
import type {
|
import type {
|
||||||
Attachment,
|
IOSAttachment,
|
||||||
AttachmentOptions,
|
IOSAttachmentOptions,
|
||||||
NativeIOSNotification,
|
NativeIOSNotification,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
export default class IOSNotification {
|
export default class IOSNotification {
|
||||||
_alertAction: string | void; // alertAction | N/A
|
_alertAction: string | void; // alertAction | N/A
|
||||||
_attachments: Attachment[]; // N/A | attachments
|
_attachments: IOSAttachment[]; // N/A | attachments
|
||||||
_badge: number | void; // applicationIconBadgeNumber | badge
|
_badge: number | void; // applicationIconBadgeNumber | badge
|
||||||
_category: string | void;
|
_category: string | void;
|
||||||
_hasAction: boolean | void; // hasAction | N/A
|
_hasAction: boolean | void; // hasAction | N/A
|
||||||
@ -40,7 +40,7 @@ export default class IOSNotification {
|
|||||||
return this._alertAction;
|
return this._alertAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
get attachments(): Attachment[] {
|
get attachments(): IOSAttachment[] {
|
||||||
return this._attachments;
|
return this._attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ export default class IOSNotification {
|
|||||||
addAttachment(
|
addAttachment(
|
||||||
identifier: string,
|
identifier: string,
|
||||||
url: string,
|
url: string,
|
||||||
options?: AttachmentOptions
|
options?: IOSAttachmentOptions
|
||||||
): Notification {
|
): Notification {
|
||||||
this._attachments.push({
|
this._attachments.push({
|
||||||
identifier,
|
identifier,
|
||||||
|
@ -115,27 +115,27 @@ export type NativeAndroidNotification = {|
|
|||||||
when?: number,
|
when?: number,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type AttachmentOptions = {|
|
export type IOSAttachmentOptions = {|
|
||||||
TypeHint: string,
|
typeHint: string,
|
||||||
ThumbnailHidden: boolean,
|
thumbnailHidden: boolean,
|
||||||
ThumbnailClippingRect: {
|
thumbnailClippingRect: {
|
||||||
height: number,
|
height: number,
|
||||||
width: number,
|
width: number,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
},
|
},
|
||||||
ThumbnailTime: number,
|
thumbnailTime: number,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type Attachment = {|
|
export type IOSAttachment = {|
|
||||||
identifier: string,
|
identifier: string,
|
||||||
options?: AttachmentOptions,
|
options?: IOSAttachmentOptions,
|
||||||
url: string,
|
url: string,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type NativeIOSNotification = {|
|
export type NativeIOSNotification = {|
|
||||||
alertAction?: string,
|
alertAction?: string,
|
||||||
attachments: Attachment[],
|
attachments: IOSAttachment[],
|
||||||
badge?: number,
|
badge?: number,
|
||||||
category?: string,
|
category?: string,
|
||||||
hasAction?: boolean,
|
hasAction?: boolean,
|
||||||
|
@ -18,7 +18,7 @@ import type {
|
|||||||
const FirebaseCoreModule = NativeModules.RNFirebase;
|
const FirebaseCoreModule = NativeModules.RNFirebase;
|
||||||
|
|
||||||
const APPS: { [string]: App } = {};
|
const APPS: { [string]: App } = {};
|
||||||
const APP_MODULES: { [App]: { [string]: FirebaseModule } } = {};
|
const APP_MODULES: { [string]: { [string]: FirebaseModule } } = {};
|
||||||
const DEFAULT_APP_NAME = '[DEFAULT]';
|
const DEFAULT_APP_NAME = '[DEFAULT]';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -49,8 +49,8 @@ export default {
|
|||||||
InstanceClass: Class<M>
|
InstanceClass: Class<M>
|
||||||
): () => FirebaseModule {
|
): () => FirebaseModule {
|
||||||
return (): M => {
|
return (): M => {
|
||||||
if (!APP_MODULES[app]) {
|
if (!APP_MODULES[app._name]) {
|
||||||
APP_MODULES[app] = {};
|
APP_MODULES[app._name] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -62,11 +62,11 @@ export default {
|
|||||||
app.utils().checkPlayServicesAvailability();
|
app.utils().checkPlayServicesAvailability();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!APP_MODULES[app][namespace]) {
|
if (!APP_MODULES[app._name][namespace]) {
|
||||||
APP_MODULES[app][namespace] = new InstanceClass(app, app.options);
|
APP_MODULES[app._name][namespace] = new InstanceClass(app, app.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
return APP_MODULES[app][namespace];
|
return APP_MODULES[app._name][namespace];
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user