Store availability state

This commit is contained in:
KemCake 2016-01-26 16:15:49 +01:00
parent 3af0809e50
commit cb95383884

View File

@ -13,6 +13,7 @@
#import "RCTUtils.h"
NSString *const RCTShortcutItemClicked = @"ShortcutItemClicked";
BOOL RCTShortcutsAvailable = false;
NSDictionary *RNQuickAction(UIApplicationShortcutItem *item) {
if (!item) return nil;
@ -32,6 +33,10 @@ RCT_EXPORT_MODULE();
@synthesize bridge = _bridge;
+ (void)initialize {
RCTShortcutsAvailable = [UIApplicationShortcutItem class] != nil;
}
- (instancetype)init
{
if ((self = [super init])) {
@ -51,7 +56,7 @@ RCT_EXPORT_MODULE();
- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
if ([UIApplicationShortcutItem class]) {
if (RCTShortcutsAvailable) {
_initialAction = [bridge.launchOptions[UIApplicationLaunchOptionsShortcutItemKey] copy];
}
}
@ -98,7 +103,7 @@ RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback)
{
if ([UIApplicationShortcutItem class]) {
if (RCTShortcutsAvailable) {
return callback(@[[NSNull null]]);
} else {
return callback(@[RCTMakeError(@"[RNQuickActions] UIApplication shortcuts are not available.", nil, nil)]);
@ -107,7 +112,7 @@ RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback)
RCT_EXPORT_METHOD(setShortcutItems:(NSArray *) shortcutItems)
{
if ([UIApplicationShortcutItem class]) {
if (RCTShortcutsAvailable) {
NSArray *dynamicShortcuts = [self dynamicShortcutItemsForPassedArray:shortcutItems];
[UIApplication sharedApplication].shortcutItems = dynamicShortcuts;
}
@ -115,7 +120,7 @@ RCT_EXPORT_METHOD(setShortcutItems:(NSArray *) shortcutItems)
RCT_EXPORT_METHOD(clearShortcutItems)
{
if ([UIApplicationShortcutItem class]) {
if (RCTShortcutsAvailable) {
[UIApplication sharedApplication].shortcutItems = nil;
}
}