Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
/*
2
 * Copyright 2019 Google
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
#import "FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.h"
18
 
19
#import "FirebaseMessaging/Sources/FIRMessagingConstants.h"
20
 
21
/// The key used to find the APNs device token in an archive.
22
static NSString *const kFIRInstanceIDAPNSInfoTokenKey = @"device_token";
23
/// The key used to find the sandbox value in an archive.
24
static NSString *const kFIRInstanceIDAPNSInfoSandboxKey = @"sandbox";
25
 
26
@interface FIRMessagingAPNSInfo ()
27
/// The APNs device token, provided by the OS to the application delegate
28
@property(nonatomic, copy) NSData *deviceToken;
29
/// Represents whether or not this is deviceToken is for the sandbox
30
/// environment, or production.
31
@property(nonatomic, getter=isSandbox) BOOL sandbox;
32
@end
33
 
34
@implementation FIRMessagingAPNSInfo
35
 
36
- (instancetype)initWithDeviceToken:(NSData *)deviceToken isSandbox:(BOOL)isSandbox {
37
  self = [super init];
38
  if (self) {
39
    _deviceToken = [deviceToken copy];
40
    _sandbox = isSandbox;
41
  }
42
  return self;
43
}
44
 
45
- (instancetype)initWithTokenOptionsDictionary:(NSDictionary *)dictionary {
46
  id deviceToken = dictionary[kFIRMessagingTokenOptionsAPNSKey];
47
  if (![deviceToken isKindOfClass:[NSData class]]) {
48
    return nil;
49
  }
50
 
51
  id isSandbox = dictionary[kFIRMessagingTokenOptionsAPNSIsSandboxKey];
52
  if (![isSandbox isKindOfClass:[NSNumber class]]) {
53
    return nil;
54
  }
55
  self = [super init];
56
  if (self) {
57
    _deviceToken = (NSData *)deviceToken;
58
    _sandbox = ((NSNumber *)isSandbox).boolValue;
59
  }
60
  return self;
61
}
62
 
63
#pragma mark - NSCopying
64
- (id)copyWithZone:(NSZone *)zone {
65
  FIRMessagingAPNSInfo *clone = [[FIRMessagingAPNSInfo alloc] init];
66
  clone.deviceToken = [_deviceToken copy];
67
  clone.sandbox = _sandbox;
68
  return clone;
69
}
70
 
71
#pragma mark - NSCoding
72
 
73
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
74
  id deviceToken = [aDecoder decodeObjectForKey:kFIRInstanceIDAPNSInfoTokenKey];
75
  if (![deviceToken isKindOfClass:[NSData class]]) {
76
    return nil;
77
  }
78
  BOOL isSandbox = [aDecoder decodeBoolForKey:kFIRInstanceIDAPNSInfoSandboxKey];
79
  return [self initWithDeviceToken:(NSData *)deviceToken isSandbox:isSandbox];
80
}
81
 
82
- (void)encodeWithCoder:(NSCoder *)aCoder {
83
  [aCoder encodeObject:self.deviceToken forKey:kFIRInstanceIDAPNSInfoTokenKey];
84
  [aCoder encodeBool:self.sandbox forKey:kFIRInstanceIDAPNSInfoSandboxKey];
85
}
86
 
87
- (BOOL)isEqualToAPNSInfo:(FIRMessagingAPNSInfo *)otherInfo {
88
  return ([self.deviceToken isEqualToData:otherInfo.deviceToken] &&
89
          self.isSandbox == otherInfo.isSandbox);
90
}
91
 
92
@end