openEventsPlatformApp/plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.m
plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.mRaw
1/*
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 */
19
20#import "CDVViewController+SplashScreen.h"
21#import <objc/runtime.h>
22
23@implementation CDVViewController (SplashScreen)
24
25@dynamic enabledAutorotation;
26
27- (void)setEnabledAutorotation:(BOOL)value
28{
29 objc_setAssociatedObject(self,
30 @selector(enabledAutorotation),
31 [NSNumber numberWithBool:value],
32 OBJC_ASSOCIATION_RETAIN_NONATOMIC);
33}
34
35- (BOOL)enabledAutorotation
36{
37 NSNumber *number = (NSNumber *)objc_getAssociatedObject(self, @selector(enabledAutorotation));
38
39 // Defaulting to YES to correspond parent CDVViewController behavior
40 if (number == nil)
41 {
42 return YES;
43 }
44
45 return [number boolValue];
46}
47
48+ (void)load
49{
50 static dispatch_once_t onceToken;
51 dispatch_once(&onceToken, ^{
52 Class class = [self class];
53
54 SEL originalSelector = @selector(shouldAutorotate);
55 SEL swizzledSelector = @selector(splash_shouldAutorotate);
56
57 Method originalMethod = class_getInstanceMethod(class, originalSelector);
58 Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
59
60 BOOL didAddMethod = class_addMethod(class,
61 originalSelector,
62 method_getImplementation(swizzledMethod),
63 method_getTypeEncoding(swizzledMethod));
64
65 if (didAddMethod) {
66 class_replaceMethod(class,
67 swizzledSelector,
68 method_getImplementation(originalMethod),
69 method_getTypeEncoding(originalMethod));
70 } else {
71 method_exchangeImplementations(originalMethod, swizzledMethod);
72 }
73 });
74}
75
76#pragma mark - Method Swizzling
77
78- (BOOL)splash_shouldAutorotate
79{
80 return self.enabledAutorotation;
81}
82
83
84- (BOOL)shouldAutorotateDefaultValue
85{
86 return [self splash_shouldAutorotate];
87}
88
89@end