first

0 parents
Showing 86 changed ファイルs with 4401 additions and 0 deletions
1 *.xcodeproj/*
2 !*.xcodeproj/project.pbxproj
3 !*.xcworkspace/contents.xcworkspacedata
4 .DS_Store
1 // AFNetworkReachabilityManager.h
2 // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21
22 #import <Foundation/Foundation.h>
23
24 #if !TARGET_OS_WATCH
25 #import <SystemConfiguration/SystemConfiguration.h>
26
27 typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
28 AFNetworkReachabilityStatusUnknown = -1,
29 AFNetworkReachabilityStatusNotReachable = 0,
30 AFNetworkReachabilityStatusReachableViaWWAN = 1,
31 AFNetworkReachabilityStatusReachableViaWiFi = 2,
32 };
33
34 NS_ASSUME_NONNULL_BEGIN
35
36 /**
37 `AFNetworkReachabilityManager` monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
38
39 Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
40
41 See Apple's Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ )
42
43 @warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined.
44 */
45 @interface AFNetworkReachabilityManager : NSObject
46
47 /**
48 The current network reachability status.
49 */
50 @property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
51
52 /**
53 Whether or not the network is currently reachable.
54 */
55 @property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;
56
57 /**
58 Whether or not the network is currently reachable via WWAN.
59 */
60 @property (readonly, nonatomic, assign, getter = isReachableViaWWAN) BOOL reachableViaWWAN;
61
62 /**
63 Whether or not the network is currently reachable via WiFi.
64 */
65 @property (readonly, nonatomic, assign, getter = isReachableViaWiFi) BOOL reachableViaWiFi;
66
67 ///---------------------
68 /// @name Initialization
69 ///---------------------
70
71 /**
72 Returns the shared network reachability manager.
73 */
74 + (instancetype)sharedManager;
75
76 /**
77 Creates and returns a network reachability manager with the default socket address.
78
79 @return An initialized network reachability manager, actively monitoring the default socket address.
80 */
81 + (instancetype)manager;
82
83 /**
84 Creates and returns a network reachability manager for the specified domain.
85
86 @param domain The domain used to evaluate network reachability.
87
88 @return An initialized network reachability manager, actively monitoring the specified domain.
89 */
90 + (instancetype)managerForDomain:(NSString *)domain;
91
92 /**
93 Creates and returns a network reachability manager for the socket address.
94
95 @param address The socket address (`sockaddr_in6`) used to evaluate network reachability.
96
97 @return An initialized network reachability manager, actively monitoring the specified socket address.
98 */
99 + (instancetype)managerForAddress:(const void *)address;
100
101 /**
102 Initializes an instance of a network reachability manager from the specified reachability object.
103
104 @param reachability The reachability object to monitor.
105
106 @return An initialized network reachability manager, actively monitoring the specified reachability.
107 */
108 - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability NS_DESIGNATED_INITIALIZER;
109
110 ///--------------------------------------------------
111 /// @name Starting & Stopping Reachability Monitoring
112 ///--------------------------------------------------
113
114 /**
115 Starts monitoring for changes in network reachability status.
116 */
117 - (void)startMonitoring;
118
119 /**
120 Stops monitoring for changes in network reachability status.
121 */
122 - (void)stopMonitoring;
123
124 ///-------------------------------------------------
125 /// @name Getting Localized Reachability Description
126 ///-------------------------------------------------
127
128 /**
129 Returns a localized string representation of the current network reachability status.
130 */
131 - (NSString *)localizedNetworkReachabilityStatusString;
132
133 ///---------------------------------------------------
134 /// @name Setting Network Reachability Change Callback
135 ///---------------------------------------------------
136
137 /**
138 Sets a callback to be executed when the network availability of the `baseURL` host changes.
139
140 @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the `baseURL`.
141 */
142 - (void)setReachabilityStatusChangeBlock:(nullable void (^)(AFNetworkReachabilityStatus status))block;
143
144 @end
145
146 ///----------------
147 /// @name Constants
148 ///----------------
149
150 /**
151 ## Network Reachability
152
153 The following constants are provided by `AFNetworkReachabilityManager` as possible network reachability statuses.
154
155 enum {
156 AFNetworkReachabilityStatusUnknown,
157 AFNetworkReachabilityStatusNotReachable,
158 AFNetworkReachabilityStatusReachableViaWWAN,
159 AFNetworkReachabilityStatusReachableViaWiFi,
160 }
161
162 `AFNetworkReachabilityStatusUnknown`
163 The `baseURL` host reachability is not known.
164
165 `AFNetworkReachabilityStatusNotReachable`
166 The `baseURL` host cannot be reached.
167
168 `AFNetworkReachabilityStatusReachableViaWWAN`
169 The `baseURL` host can be reached via a cellular connection, such as EDGE or GPRS.
170
171 `AFNetworkReachabilityStatusReachableViaWiFi`
172 The `baseURL` host can be reached via a Wi-Fi connection.
173
174 ### Keys for Notification UserInfo Dictionary
175
176 Strings that are used as keys in a `userInfo` dictionary in a network reachability status change notification.
177
178 `AFNetworkingReachabilityNotificationStatusItem`
179 A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification.
180 The corresponding value is an `NSNumber` object representing the `AFNetworkReachabilityStatus` value for the current reachability status.
181 */
182
183 ///--------------------
184 /// @name Notifications
185 ///--------------------
186
187 /**
188 Posted when network reachability changes.
189 This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability.
190
191 @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (`Prefix.pch`).
192 */
193 FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityDidChangeNotification;
194 FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityNotificationStatusItem;
195
196 ///--------------------
197 /// @name Functions
198 ///--------------------
199
200 /**
201 Returns a localized string representation of an `AFNetworkReachabilityStatus` value.
202 */
203 FOUNDATION_EXPORT NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status);
204
205 NS_ASSUME_NONNULL_END
206 #endif
1 // AFNetworkReachabilityManager.m
2 // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21
22 #import "AFNetworkReachabilityManager.h"
23 #if !TARGET_OS_WATCH
24
25 #import <netinet/in.h>
26 #import <netinet6/in6.h>
27 #import <arpa/inet.h>
28 #import <ifaddrs.h>
29 #import <netdb.h>
30
31 NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
32 NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
33
34 typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
35
36 NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status) {
37 switch (status) {
38 case AFNetworkReachabilityStatusNotReachable:
39 return NSLocalizedStringFromTable(@"Not Reachable", @"AFNetworking", nil);
40 case AFNetworkReachabilityStatusReachableViaWWAN:
41 return NSLocalizedStringFromTable(@"Reachable via WWAN", @"AFNetworking", nil);
42 case AFNetworkReachabilityStatusReachableViaWiFi:
43 return NSLocalizedStringFromTable(@"Reachable via WiFi", @"AFNetworking", nil);
44 case AFNetworkReachabilityStatusUnknown:
45 default:
46 return NSLocalizedStringFromTable(@"Unknown", @"AFNetworking", nil);
47 }
48 }
49
50 static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetworkReachabilityFlags flags) {
51 BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
52 BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
53 BOOL canConnectionAutomatically = (((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0));
54 BOOL canConnectWithoutUserInteraction = (canConnectionAutomatically && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0);
55 BOOL isNetworkReachable = (isReachable && (!needsConnection || canConnectWithoutUserInteraction));
56
57 AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
58 if (isNetworkReachable == NO) {
59 status = AFNetworkReachabilityStatusNotReachable;
60 }
61 #if TARGET_OS_IPHONE
62 else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
63 status = AFNetworkReachabilityStatusReachableViaWWAN;
64 }
65 #endif
66 else {
67 status = AFNetworkReachabilityStatusReachableViaWiFi;
68 }
69
70 return status;
71 }
72
73 /**
74 * Queue a status change notification for the main thread.
75 *
76 * This is done to ensure that the notifications are received in the same order
77 * as they are sent. If notifications are sent directly, it is possible that
78 * a queued notification (for an earlier status condition) is processed after
79 * the later update, resulting in the listener being left in the wrong state.
80 */
81 static void AFPostReachabilityStatusChange(SCNetworkReachabilityFlags flags, AFNetworkReachabilityStatusBlock block) {
82 AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
83 dispatch_async(dispatch_get_main_queue(), ^{
84 if (block) {
85 block(status);
86 }
87 NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
88 NSDictionary *userInfo = @{ AFNetworkingReachabilityNotificationStatusItem: @(status) };
89 [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:userInfo];
90 });
91 }
92
93 static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
94 AFPostReachabilityStatusChange(flags, (__bridge AFNetworkReachabilityStatusBlock)info);
95 }
96
97
98 static const void * AFNetworkReachabilityRetainCallback(const void *info) {
99 return Block_copy(info);
100 }
101
102 static void AFNetworkReachabilityReleaseCallback(const void *info) {
103 if (info) {
104 Block_release(info);
105 }
106 }
107
108 @interface AFNetworkReachabilityManager ()
109 @property (readonly, nonatomic, assign) SCNetworkReachabilityRef networkReachability;
110 @property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
111 @property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
112 @end
113
114 @implementation AFNetworkReachabilityManager
115
116 + (instancetype)sharedManager {
117 static AFNetworkReachabilityManager *_sharedManager = nil;
118 static dispatch_once_t onceToken;
119 dispatch_once(&onceToken, ^{
120 _sharedManager = [self manager];
121 });
122
123 return _sharedManager;
124 }
125
126 + (instancetype)managerForDomain:(NSString *)domain {
127 SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]);
128
129 AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
130
131 CFRelease(reachability);
132
133 return manager;
134 }
135
136 + (instancetype)managerForAddress:(const void *)address {
137 SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
138 AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
139
140 CFRelease(reachability);
141
142 return manager;
143 }
144
145 + (instancetype)manager
146 {
147 #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
148 struct sockaddr_in6 address;
149 bzero(&address, sizeof(address));
150 address.sin6_len = sizeof(address);
151 address.sin6_family = AF_INET6;
152 #else
153 struct sockaddr_in address;
154 bzero(&address, sizeof(address));
155 address.sin_len = sizeof(address);
156 address.sin_family = AF_INET;
157 #endif
158 return [self managerForAddress:&address];
159 }
160
161 - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability {
162 self = [super init];
163 if (!self) {
164 return nil;
165 }
166
167 _networkReachability = CFRetain(reachability);
168 self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
169
170 return self;
171 }
172
173 - (instancetype)init NS_UNAVAILABLE
174 {
175 return nil;
176 }
177
178 - (void)dealloc {
179 [self stopMonitoring];
180
181 if (_networkReachability != NULL) {
182 CFRelease(_networkReachability);
183 }
184 }
185
186 #pragma mark -
187
188 - (BOOL)isReachable {
189 return [self isReachableViaWWAN] || [self isReachableViaWiFi];
190 }
191
192 - (BOOL)isReachableViaWWAN {
193 return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN;
194 }
195
196 - (BOOL)isReachableViaWiFi {
197 return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi;
198 }
199
200 #pragma mark -
201
202 - (void)startMonitoring {
203 [self stopMonitoring];
204
205 if (!self.networkReachability) {
206 return;
207 }
208
209 __weak __typeof(self)weakSelf = self;
210 AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
211 __strong __typeof(weakSelf)strongSelf = weakSelf;
212
213 strongSelf.networkReachabilityStatus = status;
214 if (strongSelf.networkReachabilityStatusBlock) {
215 strongSelf.networkReachabilityStatusBlock(status);
216 }
217
218 };
219
220 SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
221 SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
222 SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
223
224 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{
225 SCNetworkReachabilityFlags flags;
226 if (SCNetworkReachabilityGetFlags(self.networkReachability, &flags)) {
227 AFPostReachabilityStatusChange(flags, callback);
228 }
229 });
230 }
231
232 - (void)stopMonitoring {
233 if (!self.networkReachability) {
234 return;
235 }
236
237 SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
238 }
239
240 #pragma mark -
241
242 - (NSString *)localizedNetworkReachabilityStatusString {
243 return AFStringFromNetworkReachabilityStatus(self.networkReachabilityStatus);
244 }
245
246 #pragma mark -
247
248 - (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block {
249 self.networkReachabilityStatusBlock = block;
250 }
251
252 #pragma mark - NSKeyValueObserving
253
254 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
255 if ([key isEqualToString:@"reachable"] || [key isEqualToString:@"reachableViaWWAN"] || [key isEqualToString:@"reachableViaWiFi"]) {
256 return [NSSet setWithObject:@"networkReachabilityStatus"];
257 }
258
259 return [super keyPathsForValuesAffectingValueForKey:key];
260 }
261
262 @end
263 #endif
1 // AFNetworking.h
2 //
3 // Copyright (c) 2013 AFNetworking (http://afnetworking.com/)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22
23 #import <Foundation/Foundation.h>
24 #import <Availability.h>
25 #import <TargetConditionals.h>
26
27 #ifndef _AFNETWORKING_
28 #define _AFNETWORKING_
29
30 #import "AFURLRequestSerialization.h"
31 #import "AFURLResponseSerialization.h"
32 #import "AFSecurityPolicy.h"
33
34 #if !TARGET_OS_WATCH
35 #import "AFNetworkReachabilityManager.h"
36 #endif
37
38 #import "AFURLSessionManager.h"
39 #import "AFHTTPSessionManager.h"
40
41 #endif /* _AFNETWORKING_ */
1 // AFSecurityPolicy.h
2 // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21
22 #import <Foundation/Foundation.h>
23 #import <Security/Security.h>
24
25 typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
26 AFSSLPinningModeNone,
27 AFSSLPinningModePublicKey,
28 AFSSLPinningModeCertificate,
29 };
30
31 /**
32 `AFSecurityPolicy` evaluates server trust against pinned X.509 certificates and public keys over secure connections.
33
34 Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.
35 */
36
37 NS_ASSUME_NONNULL_BEGIN
38
39 @interface AFSecurityPolicy : NSObject <NSSecureCoding, NSCopying>
40
41 /**
42 The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`.
43 */
44 @property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
45
46 /**
47 The certificates used to evaluate server trust according to the SSL pinning mode.
48
49 By default, this property is set to any (`.cer`) certificates included in the target compiling AFNetworking. Note that if you are using AFNetworking as embedded framework, no certificates will be pinned by default. Use `certificatesInBundle` to load certificates from your target, and then create a new policy by calling `policyWithPinningMode:withPinnedCertificates`.
50
51 Note that if pinning is enabled, `evaluateServerTrust:forDomain:` will return true if any pinned certificate matches.
52 */
53 @property (nonatomic, strong, nullable) NSSet <NSData *> *pinnedCertificates;
54
55 /**
56 Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to `NO`.
57 */
58 @property (nonatomic, assign) BOOL allowInvalidCertificates;
59
60 /**
61 Whether or not to validate the domain name in the certificate's CN field. Defaults to `YES`.
62 */
63 @property (nonatomic, assign) BOOL validatesDomainName;
64
65 ///-----------------------------------------
66 /// @name Getting Certificates from the Bundle
67 ///-----------------------------------------
68
69 /**
70 Returns any certificates included in the bundle. If you are using AFNetworking as an embedded framework, you must use this method to find the certificates you have included in your app bundle, and use them when creating your security policy by calling `policyWithPinningMode:withPinnedCertificates`.
71
72 @return The certificates included in the given bundle.
73 */
74 + (NSSet <NSData *> *)certificatesInBundle:(NSBundle *)bundle;
75
76 ///-----------------------------------------
77 /// @name Getting Specific Security Policies
78 ///-----------------------------------------
79
80 /**
81 Returns the shared default security policy, which does not allow invalid certificates, validates domain name, and does not validate against pinned certificates or public keys.
82
83 @return The default security policy.
84 */
85 + (instancetype)defaultPolicy;
86
87 ///---------------------
88 /// @name Initialization
89 ///---------------------
90
91 /**
92 Creates and returns a security policy with the specified pinning mode.
93
94 @param pinningMode The SSL pinning mode.
95
96 @return A new security policy.
97 */
98 + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode;
99
100 /**
101 Creates and returns a security policy with the specified pinning mode.
102
103 @param pinningMode The SSL pinning mode.
104 @param pinnedCertificates The certificates to pin against.
105
106 @return A new security policy.
107 */
108 + (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet <NSData *> *)pinnedCertificates;
109
110 ///------------------------------
111 /// @name Evaluating Server Trust
112 ///------------------------------
113
114 /**
115 Whether or not the specified server trust should be accepted, based on the security policy.
116
117 This method should be used when responding to an authentication challenge from a server.
118
119 @param serverTrust The X.509 certificate trust of the server.
120 @param domain The domain of serverTrust. If `nil`, the domain will not be validated.
121
122 @return Whether or not to trust the server.
123 */
124 - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
125 forDomain:(nullable NSString *)domain;
126
127 @end
128
129 NS_ASSUME_NONNULL_END
130
131 ///----------------
132 /// @name Constants
133 ///----------------
134
135 /**
136 ## SSL Pinning Modes
137
138 The following constants are provided by `AFSSLPinningMode` as possible SSL pinning modes.
139
140 enum {
141 AFSSLPinningModeNone,
142 AFSSLPinningModePublicKey,
143 AFSSLPinningModeCertificate,
144 }
145
146 `AFSSLPinningModeNone`
147 Do not used pinned certificates to validate servers.
148
149 `AFSSLPinningModePublicKey`
150 Validate host certificates against public keys of pinned certificates.
151
152 `AFSSLPinningModeCertificate`
153 Validate host certificates against pinned certificates.
154 */
1
2 /*
3
4 Copyright (c) 2013-2014 RedBearLab
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
12 */
13
14 #import <Foundation/Foundation.h>
15 #if TARGET_OS_IPHONE
16 #import <CoreBluetooth/CoreBluetooth.h>
17 #else
18 #import <IOBluetooth/IOBluetooth.h>
19 #endif
20
21 @protocol BLEDelegate
22 @optional
23 -(void) bleDidConnect;
24 -(void) bleDidDisconnect;
25 -(void) bleDidUpdateRSSI:(NSNumber *) rssi;
26 -(void) bleDidReceiveData:(unsigned char *) data length:(int) length;
27 @required
28 @end
29
30 @interface BLE : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate> {
31
32 }
33
34 @property (nonatomic,assign) id <BLEDelegate> delegate;
35 @property (strong, nonatomic) NSMutableArray *peripherals;
36 @property (strong, nonatomic) NSMutableArray *peripheralsRssi;
37 @property (strong, nonatomic) CBCentralManager *CM;
38 @property (strong, nonatomic) CBPeripheral *activePeripheral;
39
40 -(void) enableReadNotification:(CBPeripheral *)p;
41 -(void) read;
42 -(void) writeValue:(CBUUID *)serviceUUID characteristicUUID:(CBUUID *)characteristicUUID p:(CBPeripheral *)p data:(NSData *)data;
43
44 -(BOOL) isConnected;
45 -(void) write:(NSData *)d;
46 -(void) readRSSI;
47
48 -(void) controlSetup;
49 -(int) findBLEPeripherals:(int) timeout;
50 -(void) connectPeripheral:(CBPeripheral *)peripheral;
51
52 -(UInt16) swap:(UInt16) s;
53 -(const char *) centralManagerStateToString:(int)state;
54 -(void) scanTimer:(NSTimer *)timer;
55 -(void) printKnownPeripherals;
56 -(void) printPeripheralInfo:(CBPeripheral*)peripheral;
57
58 -(void) getAllServicesFromPeripheral:(CBPeripheral *)p;
59 -(void) getAllCharacteristicsFromPeripheral:(CBPeripheral *)p;
60 -(CBService *) findServiceFromUUID:(CBUUID *)UUID p:(CBPeripheral *)p;
61 -(CBCharacteristic *) findCharacteristicFromUUID:(CBUUID *)UUID service:(CBService*)service;
62
63 //-(NSString *) NSUUIDToString:(NSUUID *) UUID;
64 -(NSString *) CBUUIDToString:(CBUUID *) UUID;
65
66 -(int) compareCBUUID:(CBUUID *) UUID1 UUID2:(CBUUID *)UUID2;
67 -(int) compareCBUUIDToInt:(CBUUID *) UUID1 UUID2:(UInt16)UUID2;
68 -(UInt16) CBUUIDToInt:(CBUUID *) UUID;
69 -(BOOL) UUIDSAreEqual:(NSUUID *)UUID1 UUID2:(NSUUID *)UUID2;
70
71 @end
1
2 /*
3
4 Copyright (c) 2013-2014 RedBearLab
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
12 */
13
14 // RBL Service
15 #define RBL_SERVICE_UUID "713D0000-503E-4C75-BA94-3148F18D941E"
16 #define RBL_CHAR_TX_UUID "713D0002-503E-4C75-BA94-3148F18D941E"
17 #define RBL_CHAR_RX_UUID "713D0003-503E-4C75-BA94-3148F18D941E"
18
19 #define RBL_BLE_FRAMEWORK_VER 0x0200
1 //
2 // BootSettingController.h
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12
13 typedef enum {
14 EEPROM_WP_OFF,
15 EEPROM_WP_OFF_DONE,
16 EEPROM_WP_ON,
17 EEPROM_WP_ON_DONE,
18 FIRMWARE_IMAGE_SELECT_0,
19 FIRMWARE_IMAGE_SELECT_0_DONE,
20 FIRMWARE_IMAGE_SELECT_1,
21 FIRMWARE_IMAGE_SELECT_1_DONE,
22 RESET,
23 RESET_DONE,
24 DONE
25 } BootSettingBleCommandState;
26
27 @interface BootSettingController : UIViewController<BLEProtocolDelegate> {
28 BootSettingBleCommandState bleCommandState;
29 BootSettingBleCommandState bleCommandStateNext;
30 }
31
32 @property (strong, nonatomic) BleProtocol *protocol;
33 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
34
35 @end
1 //
2 // BootSettingController.m
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "BootSettingController.h"
10
11 @interface BootSettingController ()
12
13 @end
14
15 @implementation BootSettingController
16
17 - (void)viewDidLoad {
18 [super viewDidLoad];
19 // Do any additional setup after loading the view from its nib.
20 }
21
22 - (void)didReceiveMemoryWarning {
23 [super didReceiveMemoryWarning];
24 // Dispose of any resources that can be recreated.
25 }
26
27 - (void)viewWillAppear:(BOOL)animated {
28 self.lastProtocolDelegate = self.protocol.delegate;
29 self.protocol.delegate = self;
30 }
31
32 - (void)viewWillDisappear:(BOOL)animated {
33 self.protocol.delegate = self.lastProtocolDelegate;
34 }
35
36 - (void)showAlert:(NSString*)title message:(NSString*)message{
37 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
38 message:message
39 delegate:self
40 cancelButtonTitle:@"OK"
41 otherButtonTitles:nil];
42 [alert show];
43 }
44
45 - (IBAction)cancelButtonClicked:(id)sender {
46 [self dismissViewControllerAnimated:YES completion:Nil];
47 }
48
49 /*
50 #pragma mark - Navigation
51
52 // In a storyboard-based application, you will often want to do a little preparation before navigation
53 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
54 // Get the new view controller using [segue destinationViewController].
55 // Pass the selected object to the new view controller.
56 }
57 */
58
59 - (IBAction)selectImage0Clicked:(id)sender {
60 bleCommandState = EEPROM_WP_OFF;
61 bleCommandStateNext = FIRMWARE_IMAGE_SELECT_0;
62
63 [self bleCommandTask];
64
65 NSLog(@"selectImage0Clicked done");
66 }
67
68 - (IBAction)selectImage1Clicked:(id)sender {
69 bleCommandState = EEPROM_WP_OFF;
70 bleCommandStateNext = FIRMWARE_IMAGE_SELECT_1;
71
72 [self bleCommandTask];
73
74 NSLog(@"selectImage0Clicked done");
75 }
76
77 - (BOOL)bleCommandTask {
78 switch(bleCommandState) {
79 case EEPROM_WP_OFF:
80 [[self protocol]putData:@"eepromWriteProtect" data:@"0"];
81 break;
82 case EEPROM_WP_OFF_DONE:
83 bleCommandState = bleCommandStateNext;
84 [self bleCommandTask];
85 break;
86 case EEPROM_WP_ON:
87 [[self protocol]putData:@"eepromWriteProtect" data:@"1"];
88 break;
89 case EEPROM_WP_ON_DONE:
90 bleCommandState = DONE;
91 [self bleCommandTask];
92 break;
93 case FIRMWARE_IMAGE_SELECT_0:
94 [[self protocol]putData:@"firmwareImageSelect" data:@"0"];
95 break;
96 case FIRMWARE_IMAGE_SELECT_0_DONE:
97 bleCommandState = EEPROM_WP_ON;
98 [self bleCommandTask];
99 break;
100 case FIRMWARE_IMAGE_SELECT_1:
101 [[self protocol]putData:@"firmwareImageSelect" data:@"1"];
102 break;
103 case FIRMWARE_IMAGE_SELECT_1_DONE:
104 bleCommandState = EEPROM_WP_ON;
105 [self bleCommandTask];
106 break;
107 case RESET:
108 [[self protocol]putData:@"systemReset" data:nil];
109 break;
110 case RESET_DONE:
111 {
112 NSLog(@"Ble command set done!");
113 break;
114 }
115 case DONE:
116 {
117 NSLog(@"Ble command set done!");
118 [self showAlert:@"EEPROM書き込み" message:@"EEPROMに保存しました。"];
119 break;
120 }
121 }
122 return false;
123 }
124
125 - (void)protocolDidGetData:(NSString *)dataType data:(NSString *)dataData {
126 if([dataType isEqualToString:@"firmwareImageSelect"]) {
127 if([dataData isEqualToString:@"0"]) {
128 NSLog(@"firmwareImageSelect 0");
129 bleCommandState = FIRMWARE_IMAGE_SELECT_0_DONE;
130 [self bleCommandTask];
131 } else if([dataData isEqualToString:@"1"]) {
132 NSLog(@"firmwareImageSelect 1");
133 bleCommandState = FIRMWARE_IMAGE_SELECT_1_DONE;
134 [self bleCommandTask];
135 }
136 } else if([dataType isEqualToString:@"eepromWriteProtect"]) {
137 if([dataData isEqualToString:@"0"]) {
138 NSLog(@"eepromWriteProtect 0");
139 bleCommandState = EEPROM_WP_OFF_DONE;
140 [self bleCommandTask];
141 } else if([dataData isEqualToString:@"1"]) {
142 NSLog(@"eepromWriteProtect 1");
143 bleCommandState = EEPROM_WP_ON_DONE;
144 [self bleCommandTask];
145 }
146 } else if([dataType isEqualToString:@"systemReset"]) {
147 NSLog(@"systemReset");
148 bleCommandState = RESET_DONE;
149 [self bleCommandTask];
150 }
151 }
152
153 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <deployment identifier="iOS"/>
8 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="BootSettingController">
13 <connections>
14 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
15 </connections>
16 </placeholder>
17 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
18 <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
19 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
20 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
21 <subviews>
22 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fTM-mh-INi">
23 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
24 <items>
25 <navigationItem title="起動設定" id="gUm-My-XyB">
26 <barButtonItem key="leftBarButtonItem" title="戻る" id="FKk-cz-oNn">
27 <connections>
28 <action selector="cancelButtonClicked:" destination="-1" id="2WK-pK-yx1"/>
29 </connections>
30 </barButtonItem>
31 </navigationItem>
32 </items>
33 </navigationBar>
34 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LXt-Fp-Egr">
35 <rect key="frame" x="149" y="157" width="77" height="30"/>
36 <state key="normal" title="イメージ1"/>
37 <connections>
38 <action selector="selectImage1Clicked:" destination="-1" eventType="touchUpInside" id="3DN-JD-Fh5"/>
39 </connections>
40 </button>
41 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xKp-zn-ktL">
42 <rect key="frame" x="95" y="97" width="184" height="30"/>
43 <state key="normal" title="ファームウェア更新モード"/>
44 <connections>
45 <action selector="selectImage0Clicked:" destination="-1" eventType="touchUpInside" id="Hfa-rm-ZOf"/>
46 </connections>
47 </button>
48 </subviews>
49 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
50 <constraints>
51 <constraint firstItem="xKp-zn-ktL" firstAttribute="top" secondItem="fTM-mh-INi" secondAttribute="bottom" constant="30" id="1On-Cz-oFe"/>
52 <constraint firstItem="fTM-mh-INi" firstAttribute="centerX" secondItem="xKp-zn-ktL" secondAttribute="centerX" id="8Vf-o5-eah"/>
53 <constraint firstAttribute="trailing" secondItem="fTM-mh-INi" secondAttribute="trailing" id="9Fe-2W-A8G"/>
54 <constraint firstItem="xKp-zn-ktL" firstAttribute="centerX" secondItem="LXt-Fp-Egr" secondAttribute="centerX" id="N6N-OR-fWN"/>
55 <constraint firstItem="LXt-Fp-Egr" firstAttribute="top" secondItem="xKp-zn-ktL" secondAttribute="bottom" constant="30" id="ZOf-Ae-7hS"/>
56 <constraint firstItem="fTM-mh-INi" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="iZR-EP-iEa"/>
57 <constraint firstItem="xKp-zn-ktL" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="kul-HK-4Cd"/>
58 <constraint firstItem="fTM-mh-INi" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="23" id="m5P-3V-zcJ"/>
59 <constraint firstItem="LXt-Fp-Egr" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="wEs-z8-waM"/>
60 </constraints>
61 </view>
62 </objects>
63 </document>
1 //
2 // DBManager.h
3 // SQLite3DBSample
4 //
5 // Created by ドラッサル 亜嵐 on 2016/02/03.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10
11 @protocol DBManagerDelegate
12 @optional
13 - (void)gotData:(NSString *)data;
14 @required
15 @end
16
17 @interface DBManager : NSObject
18 @property (nonatomic,assign) id <DBManagerDelegate> delegate;
19 @property (nonatomic, strong) NSMutableArray *arrColumnNames;
20 @property (nonatomic) int affectedRows;
21 @property (nonatomic) long long lastInsertedRowID;
22
23 -(NSArray *)loadDataFromDB:(NSString *)query;
24 -(void)executeQuery:(NSString *)query;
25 - (NSArray*)getFirmwareDataList;
26 - (NSArray*)getEepromTemplateData;
27 - (bool)saveFirmwareData:(NSString *)uuid
28 deviceType:(NSString *)deviceType
29 deviceModel:(NSString *)deviceModel
30 version:(NSString *)version
31 versionStamp:(NSString *)versionStamp
32 file:(NSString *)file;
33 - (bool)saveEepromTemplateData:(NSString *)recordId
34 recordName:(NSString *)recordName
35 dataId:(NSString *)dataId
36 deviceModel:(NSString *)dataModel
37 dataType:(NSString *)dataType
38 dataOs:(NSString *)dataOs
39 dataPin:(NSString *)dataPin;
40 - (bool)deleteFirmwareData:(NSString *)recordId;
41 - (bool)deleteEepromTemplateData:(NSString *)recordId;
42
43 + (NSString*) createDatabaseIfRequiredAtPath:(NSString*)databasePath;
44
45 + (instancetype)sharedInstance;
46
47 @end
1 //
2 // DemoView.swift
3 // jacket_test_ios
4 //
5 // Created by USER on 2017/10/11.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 import UIKit
10
11 class DemoView: UIView {
12
13
14 // Only override draw() if you perform custom drawing.
15 // An empty implementation adversely affects performance during animation.
16 override func draw(_ rect: CGRect) {
17 // Drawing code
18 let label = UILabel()
19 label.text = "Demo"
20 label.sizeToFit()
21 self.addSubview(label)
22
23 }
24
25
26 }
1 //
2 // EepromController.h
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12 #import "EepromTemplateController.h"
13
14 typedef enum {
15 EEPROM__EEPROM_WP_OFF,
16 EEPROM__EEPROM_WP_OFF_DONE,
17 EEPROM__EEPROM_WP_ON,
18 EEPROM__EEPROM_WP_ON_DONE,
19 EEPROM__EEPROM_READ_ID,
20 EEPROM__EEPROM_READ_ID_DONE,
21 EEPROM__EEPROM_READ_MODEL,
22 EEPROM__EEPROM_READ_MODEL_DONE,
23 EEPROM__EEPROM_READ_TYPE,
24 EEPROM__EEPROM_READ_TYPE_DONE,
25 EEPROM__EEPROM_READ_OS,
26 EEPROM__EEPROM_READ_OS_DONE,
27 EEPROM__EEPROM_READ_PIN,
28 EEPROM__EEPROM_READ_PIN_DONE,
29 EEPROM__EEPROM_WRITE_ID,
30 EEPROM__EEPROM_WRITE_ID_DONE,
31 EEPROM__EEPROM_WRITE_MODEL,
32 EEPROM__EEPROM_WRITE_MODEL_DONE,
33 EEPROM__EEPROM_WRITE_TYPE,
34 EEPROM__EEPROM_WRITE_TYPE_DONE,
35 EEPROM__EEPROM_WRITE_OS,
36 EEPROM__EEPROM_WRITE_OS_DONE,
37 EEPROM__EEPROM_WRITE_PIN,
38 EEPROM__EEPROM_WRITE_PIN_DONE,
39 EEPROM__DONE
40 } EepromCommandState;
41
42 @interface EepromController : UIViewController<EepromTemplateControllerDelegate, BLEProtocolDelegate> {
43 IBOutlet UITextField *txtId;
44 IBOutlet UITextField *txtModel;
45 IBOutlet UITextField *txtType;
46 IBOutlet UITextField *txtOs;
47 IBOutlet UITextField *txtPin;
48 NSString *strId;
49 NSString *strModel;
50 NSString *strType;
51 NSString *strOs;
52 NSString *strPin;
53 EepromCommandState bleCommandState;
54 IBOutlet UIScrollView *scrollView;
55 UITextField *activeField;
56 }
57
58 - (IBAction)cancelButtonClicked:(id)sender;
59 - (IBAction)saveButtonClicked:(id)sender;
60
61 @property (strong, nonatomic) BleProtocol *protocol;
62 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
63
64 @end
1 //
2 // EepromTemplateController.h
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @protocol EepromTemplateControllerDelegate
12 @optional
13 - (void)didChoose:(NSString *)recordId
14 recordName:(NSString *)recordName
15 dataId:(NSString *)dataId
16 dataModel:(NSString *)dataModel
17 dataType:(NSString *)dataType
18 dataOs:(NSString *)dataOs
19 dataPin:(NSString *)dataPin;
20 @required
21 @end
22
23 @interface EepromTemplateController : UIViewController<UITableViewDelegate, UITableViewDataSource> {
24 IBOutlet UITableView *tblResult;
25 NSMutableArray *arrResult;
26 }
27
28 @property (nonatomic,assign) id <EepromTemplateControllerDelegate> delegate;
29
30 @end
1 //
2 // EepromTemplateController.m
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "EepromTemplateController.h"
10 #import "EepromTemplateTableViewCell.h"
11 #import "DBManager.h"
12
13 @interface EepromTemplateController ()
14
15 @end
16
17 @implementation EepromTemplateController
18
19 - (void)viewDidLoad {
20 [super viewDidLoad];
21 // Do any additional setup after loading the view from its nib.
22 }
23
24 - (void)viewWillAppear:(BOOL)animated {
25 arrResult = [[NSMutableArray alloc] init];
26
27 UINib *nib = [UINib nibWithNibName:@"EepromTemplateTableViewCell" bundle:nil];
28 [tblResult registerNib:nib forCellReuseIdentifier:@"mycell"];
29 tblResult.delegate = self;
30 tblResult.dataSource = self;
31
32 [arrResult removeAllObjects];
33
34 NSArray *result = [[DBManager sharedInstance] getEepromTemplateData];
35
36 for(id key in result) {
37 NSString *valueRecordId = [key objectAtIndex:0];
38 NSString *valueRecordName = [key objectAtIndex:1];
39 NSString *valueDataId = [key objectAtIndex:2];
40 NSString *valueDataModel = [key objectAtIndex:3];
41 NSString *valueDataType = [key objectAtIndex:4];
42 NSString *valueDataOs = [key objectAtIndex:5];
43 NSString *valueDataPin = [key objectAtIndex:6];
44
45 NSMutableDictionary *newDict = [NSMutableDictionary dictionary];
46 [newDict setObject:valueRecordId forKey:@"recordId"];
47 [newDict setObject:valueRecordName forKey:@"recordName"];
48 [newDict setObject:valueDataId forKey:@"dataId"];
49 [newDict setObject:valueDataModel forKey:@"dataModel"];
50 [newDict setObject:valueDataType forKey:@"dataType"];
51 [newDict setObject:valueDataOs forKey:@"dataOs"];
52 [newDict setObject:valueDataPin forKey:@"dataPin"];
53
54 [arrResult addObject:newDict];
55 }
56 [tblResult reloadData];
57 }
58
59 - (void)didReceiveMemoryWarning {
60 [super didReceiveMemoryWarning];
61 // Dispose of any resources that can be recreated.
62 }
63
64 - (IBAction)cancelButtonClicked:(id)sender {
65 [self dismissViewControllerAnimated:YES completion:Nil];
66 }
67
68 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
69 NSInteger row = [indexPath row];
70 NSDictionary *dataRecord = [arrResult objectAtIndex:row];
71
72 [self.delegate didChoose:[dataRecord valueForKey:@"recordId"]
73 recordName:[dataRecord valueForKey:@"recordName"]
74 dataId:[dataRecord valueForKey:@"dataId"]
75 dataModel:[dataRecord valueForKey:@"dataModel"]
76 dataType:[dataRecord valueForKey:@"dataType"]
77 dataOs:[dataRecord valueForKey:@"dataOs"]
78 dataPin:[dataRecord valueForKey:@"dataPin"]];
79 [self dismissViewControllerAnimated:YES completion:Nil];
80 }
81
82 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
83 // Return the number of sections.
84 return 1;
85 }
86
87 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
88 // Return the number of rows in the section.
89 return [arrResult count];
90 }
91
92 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
93 {
94 static NSString *cellIdentifier = @"mycell";
95 EepromTemplateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
96
97 NSInteger row = [indexPath row];
98 NSDictionary *dataRecord = [arrResult objectAtIndex:row];
99
100 // Configure the cell...
101 UIFont *newFont = [UIFont fontWithName:@"Arial" size:17.0];
102 cell.lblRecordName.font = newFont;
103 cell.lblRecordName.text = [dataRecord valueForKey:@"recordName"];
104
105 newFont = [UIFont fontWithName:@"Arial" size:12.0];
106 cell.lblRecordId.font = newFont;
107 cell.lblRecordId.text = [dataRecord valueForKey:@"recordId"];
108
109 cell.lblDataId.font = newFont;
110 cell.lblDataId.text = [dataRecord valueForKey:@"dataId"];
111
112 cell.lblDataModel.font = newFont;
113 cell.lblDataModel.text = [dataRecord valueForKey:@"dataModel"];
114
115 cell.lblDataType.font = newFont;
116 cell.lblDataType.text = [dataRecord valueForKey:@"dataType"];
117
118 cell.lblDataOs.font = newFont;
119 cell.lblDataOs.text = [dataRecord valueForKey:@"dataOs"];
120
121 cell.lblDataPin.font = newFont;
122 cell.lblDataPin.text = [dataRecord valueForKey:@"dataPin"];
123
124 return cell;
125 }
126
127 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
128 {
129 return 100;
130 }
131
132 - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
133 {
134 return @[
135 [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive
136 title:@"削除"
137 handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
138 // own delete action
139
140
141 // Distructive button tapped.
142 NSLog(@"削除の確認");
143
144 NSDictionary * selectedData = [arrResult objectAtIndex:indexPath.row];
145 NSString *firmwareTitle = [selectedData valueForKey:@"file"];
146
147 UIAlertController *actionSheetConfirm = [UIAlertController alertControllerWithTitle:@"削除の確認" message:[NSString stringWithFormat:@"「%@」を削除します。よろしいですか?",firmwareTitle] preferredStyle:UIAlertControllerStyleAlert];
148
149 [actionSheetConfirm addAction:[UIAlertAction actionWithTitle:@"削除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *actionConfirm) {
150
151
152 // Get the record ID of the selected name and set it to the recordIDToEdit property.
153 NSDictionary * selectedData = [arrResult objectAtIndex:indexPath.row];
154
155 NSString *recordId = [selectedData valueForKey:@"recordId"];
156 NSLog(@"recordId = %@",recordId);
157
158 [[DBManager sharedInstance] deleteEepromTemplateData:recordId];
159 //[self populateDetail];
160 //[self.tblResult reloadData];
161 [arrResult removeObjectAtIndex:indexPath.row];
162 [tblResult deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
163 }]];
164 [actionSheetConfirm addAction:[UIAlertAction actionWithTitle:@"キャンセル" style:UIAlertActionStyleDefault handler:^(UIAlertAction *actionConfirm) {
165 // Distructive button tapped.
166 NSLog(@"キャンセルの確認");
167 }]];
168 [self presentViewController:actionSheetConfirm animated:YES completion:nil];
169 }],
170 ];
171 }
172
173 /*
174 #pragma mark - Navigation
175
176 // In a storyboard-based application, you will often want to do a little preparation before navigation
177 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
178 // Get the new view controller using [segue destinationViewController].
179 // Pass the selected object to the new view controller.
180 }
181 */
182
183 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <deployment identifier="iOS"/>
8 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="EepromTemplateController">
13 <connections>
14 <outlet property="tblResult" destination="ApV-bw-Rn1" id="zPh-Vf-P8V"/>
15 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
16 </connections>
17 </placeholder>
18 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
19 <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
20 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
22 <subviews>
23 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="tFr-RW-xCk">
24 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
25 <items>
26 <navigationItem title="テンプレート選択" id="9cH-Zh-eej">
27 <barButtonItem key="leftBarButtonItem" title="戻る" id="u5c-K3-4uI">
28 <connections>
29 <action selector="cancelButtonClicked:" destination="-1" id="45e-6T-qfA"/>
30 </connections>
31 </barButtonItem>
32 </navigationItem>
33 </items>
34 </navigationBar>
35 <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="ApV-bw-Rn1">
36 <rect key="frame" x="0.0" y="67" width="375" height="600"/>
37 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
38 </tableView>
39 </subviews>
40 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
41 <constraints>
42 <constraint firstItem="tFr-RW-xCk" firstAttribute="leading" secondItem="ApV-bw-Rn1" secondAttribute="leading" id="4cX-M9-u63"/>
43 <constraint firstItem="tFr-RW-xCk" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="23" id="6cd-hA-zhv"/>
44 <constraint firstAttribute="bottom" secondItem="ApV-bw-Rn1" secondAttribute="bottom" id="9Qe-KE-6Ho"/>
45 <constraint firstItem="tFr-RW-xCk" firstAttribute="trailing" secondItem="ApV-bw-Rn1" secondAttribute="trailing" id="FXl-z1-bN7"/>
46 <constraint firstItem="tFr-RW-xCk" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="NGB-Xr-cIf"/>
47 <constraint firstAttribute="trailing" secondItem="tFr-RW-xCk" secondAttribute="trailing" id="ZyS-Vn-LV4"/>
48 <constraint firstItem="ApV-bw-Rn1" firstAttribute="top" secondItem="tFr-RW-xCk" secondAttribute="bottom" id="ad4-Qe-Nod"/>
49 </constraints>
50 <point key="canvasLocation" x="24.5" y="52.5"/>
51 </view>
52 </objects>
53 </document>
1 //
2 // EepromTemplateTableViewCell.h
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @interface EepromTemplateTableViewCell : UITableViewCell
12
13 @property (strong, nonatomic) IBOutlet UILabel *lblRecordId;
14 @property (strong, nonatomic) IBOutlet UILabel *lblRecordName;
15 @property (strong, nonatomic) IBOutlet UILabel *lblDataId;
16 @property (strong, nonatomic) IBOutlet UILabel *lblDataModel;
17 @property (strong, nonatomic) IBOutlet UILabel *lblDataType;
18 @property (strong, nonatomic) IBOutlet UILabel *lblDataOs;
19 @property (strong, nonatomic) IBOutlet UILabel *lblDataPin;
20
21 @end
1 //
2 // EepromTemplateTableViewCell.m
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/07/24.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "EepromTemplateTableViewCell.h"
10
11 @implementation EepromTemplateTableViewCell
12 @synthesize lblRecordId = _lblRecordId;
13 @synthesize lblRecordName = _lblRecordName;
14 @synthesize lblDataId = _lblDataId;
15 @synthesize lblDataModel = _lblDataModel;
16 @synthesize lblDataType = _lblDataType;
17 @synthesize lblDataOs = _lblDataOs;
18 @synthesize lblDataPin = _lblDataPin;
19
20 - (void)awakeFromNib {
21 [super awakeFromNib];
22 // Initialization code
23 }
24
25 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
26 [super setSelected:selected animated:animated];
27
28 // Configure the view for the selected state
29 }
30
31 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <deployment identifier="iOS"/>
8 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
9 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
10 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
11 </dependencies>
12 <objects>
13 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
14 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
15 <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="100" id="KGk-i7-Jjw" customClass="EepromTemplateTableViewCell">
16 <rect key="frame" x="0.0" y="0.0" width="320" height="100"/>
17 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
18 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
19 <rect key="frame" x="0.0" y="0.0" width="320" height="99.5"/>
20 <autoresizingMask key="autoresizingMask"/>
21 <subviews>
22 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="recordId" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8fS-9z-HJ1">
23 <rect key="frame" x="8" y="0.0" width="304" height="15"/>
24 <fontDescription key="fontDescription" type="system" pointSize="12"/>
25 <nil key="textColor"/>
26 <nil key="highlightedColor"/>
27 </label>
28 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dataId" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ehd-h0-G5F">
29 <rect key="frame" x="8" y="30" width="304" height="14.5"/>
30 <fontDescription key="fontDescription" type="system" pointSize="12"/>
31 <nil key="textColor"/>
32 <nil key="highlightedColor"/>
33 </label>
34 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dataModel" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gwb-VU-QNL">
35 <rect key="frame" x="8" y="44" width="304" height="14.5"/>
36 <fontDescription key="fontDescription" type="system" pointSize="12"/>
37 <nil key="textColor"/>
38 <nil key="highlightedColor"/>
39 </label>
40 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dataType" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gc3-Sq-C9l">
41 <rect key="frame" x="8" y="58" width="304" height="14.5"/>
42 <fontDescription key="fontDescription" type="system" pointSize="12"/>
43 <nil key="textColor"/>
44 <nil key="highlightedColor"/>
45 </label>
46 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dataOs" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="458-dR-dVU">
47 <rect key="frame" x="8" y="71" width="304" height="14.5"/>
48 <fontDescription key="fontDescription" type="system" pointSize="12"/>
49 <nil key="textColor"/>
50 <nil key="highlightedColor"/>
51 </label>
52 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="recordName" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iT0-XG-TUh">
53 <rect key="frame" x="8" y="12" width="304" height="21"/>
54 <fontDescription key="fontDescription" type="system" pointSize="17"/>
55 <nil key="textColor"/>
56 <nil key="highlightedColor"/>
57 </label>
58 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="dataPin" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eOf-Vq-Ned">
59 <rect key="frame" x="8" y="83" width="43" height="15"/>
60 <fontDescription key="fontDescription" type="system" pointSize="12"/>
61 <nil key="textColor"/>
62 <nil key="highlightedColor"/>
63 </label>
64 </subviews>
65 <constraints>
66 <constraint firstItem="Gwb-VU-QNL" firstAttribute="top" secondItem="iT0-XG-TUh" secondAttribute="bottom" constant="11" id="3Ah-wp-nlD"/>
67 <constraint firstAttribute="trailingMargin" secondItem="458-dR-dVU" secondAttribute="trailing" id="3q1-IV-Uu4"/>
68 <constraint firstItem="458-dR-dVU" firstAttribute="top" secondItem="Gwb-VU-QNL" secondAttribute="bottom" constant="12.5" id="662-hh-xov"/>
69 <constraint firstAttribute="trailingMargin" secondItem="Gc3-Sq-C9l" secondAttribute="trailing" id="87s-sY-8PO"/>
70 <constraint firstItem="8fS-9z-HJ1" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="95Q-rK-8K6"/>
71 <constraint firstItem="ehd-h0-G5F" firstAttribute="top" secondItem="8fS-9z-HJ1" secondAttribute="bottom" constant="15" id="LQ7-1v-xOY"/>
72 <constraint firstAttribute="trailingMargin" secondItem="Gwb-VU-QNL" secondAttribute="trailing" id="NcB-sA-bvl"/>
73 <constraint firstItem="iT0-XG-TUh" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="4" id="QJJ-js-QYu"/>
74 <constraint firstItem="ehd-h0-G5F" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="RC0-Ar-tZX"/>
75 <constraint firstItem="iT0-XG-TUh" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="VkX-0A-hRU"/>
76 <constraint firstItem="Gwb-VU-QNL" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="Vzs-yL-Pmn"/>
77 <constraint firstItem="eOf-Vq-Ned" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="8" id="Xaf-Xh-Ozw"/>
78 <constraint firstItem="Gc3-Sq-C9l" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="bQ8-Fy-ebk"/>
79 <constraint firstItem="Gc3-Sq-C9l" firstAttribute="top" secondItem="ehd-h0-G5F" secondAttribute="bottom" constant="13.5" id="bTK-je-YxG"/>
80 <constraint firstItem="458-dR-dVU" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="d0r-nI-b5G"/>
81 <constraint firstAttribute="trailingMargin" secondItem="iT0-XG-TUh" secondAttribute="trailing" id="htH-3d-fAh"/>
82 <constraint firstAttribute="trailingMargin" secondItem="8fS-9z-HJ1" secondAttribute="trailing" id="iRy-KW-NVN"/>
83 <constraint firstItem="eOf-Vq-Ned" firstAttribute="top" secondItem="Gc3-Sq-C9l" secondAttribute="bottom" constant="10.5" id="lNL-bx-aIK"/>
84 <constraint firstAttribute="trailingMargin" secondItem="ehd-h0-G5F" secondAttribute="trailing" id="mwI-LD-DKm"/>
85 <constraint firstItem="8fS-9z-HJ1" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="ygd-9l-fh7"/>
86 </constraints>
87 </tableViewCellContentView>
88 <connections>
89 <outlet property="lblDataId" destination="ehd-h0-G5F" id="zNI-oH-grq"/>
90 <outlet property="lblDataModel" destination="Gwb-VU-QNL" id="UfO-sd-eLM"/>
91 <outlet property="lblDataOs" destination="458-dR-dVU" id="RBV-15-xGE"/>
92 <outlet property="lblDataPin" destination="eOf-Vq-Ned" id="5fK-t6-Guw"/>
93 <outlet property="lblDataType" destination="Gc3-Sq-C9l" id="G49-kF-3gj"/>
94 <outlet property="lblRecordId" destination="8fS-9z-HJ1" id="oAa-nz-13w"/>
95 <outlet property="lblRecordName" destination="iT0-XG-TUh" id="LAb-QQ-lFu"/>
96 </connections>
97 <point key="canvasLocation" x="25" y="80"/>
98 </tableViewCell>
99 </objects>
100 </document>
1 //
2 // FirmwareDownloadController.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11
12 typedef enum {
13 FIRMWARE_DOWNLOAD__EEPROM_READ_ID,
14 FIRMWARE_DOWNLOAD__EEPROM_READ_ID_DONE,
15 FIRMWARE_DOWNLOAD__EEPROM_READ_MODEL,
16 FIRMWARE_DOWNLOAD__EEPROM_READ_MODEL_DONE,
17 FIRMWARE_DOWNLOAD__EEPROM_READ_TYPE,
18 FIRMWARE_DOWNLOAD__EEPROM_READ_TYPE_DONE,
19 FIRMWARE_DOWNLOAD__EEPROM_READ_OS,
20 FIRMWARE_DOWNLOAD__EEPROM_READ_OS_DONE,
21 FIRMWARE_DOWNLOAD__DONE
22 } FirmwareDownloadCommandState;
23
24 @interface FirmwareDownloadController : UIViewController<UITableViewDelegate, UITableViewDataSource, BLEProtocolDelegate> {
25 IBOutlet UITableView *tblFirmware;
26 IBOutlet UILabel *lblPercentComplete;
27 NSMutableArray *arrResult;
28 int selectionEnabled;
29
30 NSString *strId;
31 NSString *strModel;
32 NSString *strType;
33 NSString *strOs;
34 FirmwareDownloadCommandState bleCommandState;
35 }
36
37 @property (strong, nonatomic) BleProtocol *protocol;
38 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
39
40 @end
1 //
2 // FirmwareDownloadController.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "FirmwareDownloadController.h"
10 #import "FirmwareDownloadControllerTableViewCell.h"
11 #import "Operation.h"
12 #import "DBManager.h"
13
14 @interface FirmwareDownloadController ()
15
16 @end
17
18 @implementation FirmwareDownloadController
19
20 - (void)viewDidLoad {
21 [super viewDidLoad];
22 // Do any additional setup after loading the view from its nib.
23 }
24
25 - (void)viewWillAppear:(BOOL)animated {
26 self.lastProtocolDelegate = self.protocol.delegate;
27 self.protocol.delegate = self;
28
29 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_ID;
30 [self bleCommandTask];
31 }
32
33 - (void)viewWillDisappear:(BOOL)animated {
34 self.protocol.delegate = self.lastProtocolDelegate;
35 }
36
37 - (void)didReceiveMemoryWarning {
38 [super didReceiveMemoryWarning];
39 // Dispose of any resources that can be recreated.
40 }
41
42 - (void) getDownloadList {
43 selectionEnabled = 1;
44
45 arrResult = [[NSMutableArray alloc] init];
46
47 UINib *nib = [UINib nibWithNibName:@"FirmwareDownloadControllerTableViewCell" bundle:nil];
48 [tblFirmware registerNib:nib forCellReuseIdentifier:@"mycell"];
49 tblFirmware.delegate = self;
50 tblFirmware.dataSource = self;
51
52 [[Operation sharedOperation] getFirmwareList:strId
53 deviceType:strType
54 deviceModel:strModel
55 deviceOs:strOs
56 appVersion:@"appVersion"
57 success:^(id JSON) {
58 NSLog(@"SUCCESS!");
59
60 if([JSON valueForKey:@"firmware_list"]) {
61 [arrResult removeAllObjects];
62
63 NSDictionary *firmwareList = [JSON valueForKey:@"firmware_list"];
64
65 for(id selectedKey in firmwareList) {
66 NSDictionary *firmwareListRecord = [firmwareList valueForKey:selectedKey];
67 NSMutableDictionary *detailDict = [[NSMutableDictionary alloc] init];
68 [detailDict setValue:selectedKey forKey:@"uuid"];
69 for(id selectedSubKey in firmwareListRecord) {
70 [detailDict setValue:[firmwareListRecord valueForKey:selectedSubKey] forKey:selectedSubKey];
71 }
72 [arrResult addObject:detailDict];
73 }
74 }
75 [tblFirmware reloadData];
76 } failure:^(NSError *error, id JSON) {
77 NSLog(@"FAIL!");
78 }];
79 }
80
81 - (IBAction)cancelButtonClicked:(id)sender {
82 [self dismissViewControllerAnimated:YES completion:Nil];
83 }
84
85 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
86 if(selectionEnabled == 1) {
87 return indexPath;
88 } else {
89 return nil;
90 }
91 }
92
93 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
94 NSInteger row = [indexPath row];
95 NSDictionary *dataRecord = [arrResult objectAtIndex:row];
96
97 NSString *filename = [dataRecord valueForKey:@"uuid"];
98
99 selectionEnabled = 0;
100
101 [[Operation sharedOperation] streamToFile:[NSString stringWithFormat:@"%@%@",URL_BASE,[NSString stringWithFormat:URL_PATH_STORE_FIRMWARE, filename]]
102 saveToPath:[NSString stringWithFormat:@"save/%@",filename]
103 progressBlock:^(double fractionCompleted) {
104 //NSLog(@"Progress: %f", fractionCompleted);
105 lblPercentComplete.text = [NSString stringWithFormat:@"%f%%", fractionCompleted * 100];
106 }
107 success:^(NSString *savedTo) {
108 NSLog(@"Saved to %@",savedTo);
109 [[DBManager sharedInstance] saveFirmwareData:[dataRecord valueForKey:@"uuid"]
110 deviceType:[dataRecord valueForKey:@"devicetype"]
111 deviceModel:[dataRecord valueForKey:@"devicemodel"]
112 version:[dataRecord valueForKey:@"version"]
113 versionStamp:[dataRecord valueForKey:@"version_Stamp"]
114 file:[dataRecord valueForKey:@"file"]];
115 //[self saveVideoInfo:video.identifier videoItag:[NSString stringWithFormat:@"%@",videoQuality] videoFilename:[NSString stringWithFormat:@"%@_%@.mp4",video.identifier,videoQuality]];
116 //[self showAlert:@"アプリに保存" message:@"保存完了"];
117 selectionEnabled = 1;
118 lblPercentComplete.text = @"完了";
119 }
120 failure:^(NSError *error) {
121 //[self showAlert:@"アプリに保存" message:@"保存完了"];
122 selectionEnabled = 1;
123 lblPercentComplete.text = @"失敗";
124 }];
125 }
126
127 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
128 // Return the number of sections.
129 return 1;
130 }
131
132 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
133 // Return the number of rows in the section.
134 return [arrResult count];
135 }
136
137 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
138 {
139 static NSString *cellIdentifier = @"mycell";
140 FirmwareDownloadControllerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
141
142 NSInteger row = [indexPath row];
143 NSDictionary *dataRecord = [arrResult objectAtIndex:row];
144
145 // Configure the cell...
146 UIFont *newFont = [UIFont fontWithName:@"Arial" size:11.0];
147 cell.lblTitle.font = newFont;
148 cell.lblTitle.text = [dataRecord valueForKey:@"file"];
149
150 newFont = [UIFont fontWithName:@"Arial" size:11.0];
151 cell.lblSubtitle.font = newFont;
152 cell.lblSubtitle.text = [dataRecord valueForKey:@"uuid"];
153
154 return cell;
155 }
156
157 - (BOOL)bleCommandTask {
158 switch(bleCommandState) {
159 case FIRMWARE_DOWNLOAD__EEPROM_READ_ID:
160 [[self protocol]putData:@"infoDeviceId" data:nil];
161 break;
162 case FIRMWARE_DOWNLOAD__EEPROM_READ_MODEL:
163 [[self protocol]putData:@"infoDeviceModel" data:nil];
164 break;
165 case FIRMWARE_DOWNLOAD__EEPROM_READ_TYPE:
166 [[self protocol]putData:@"infoDeviceType" data:nil];
167 break;
168 case FIRMWARE_DOWNLOAD__EEPROM_READ_OS:
169 [[self protocol]putData:@"infoDeviceOs" data:nil];
170 break;
171 case FIRMWARE_DOWNLOAD__EEPROM_READ_ID_DONE:
172 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_MODEL;
173 [self bleCommandTask];
174 break;
175 case FIRMWARE_DOWNLOAD__EEPROM_READ_MODEL_DONE:
176 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_TYPE;
177 [self bleCommandTask];
178 break;
179 case FIRMWARE_DOWNLOAD__EEPROM_READ_TYPE_DONE:
180 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_OS;
181 [self bleCommandTask];
182 break;
183 case FIRMWARE_DOWNLOAD__EEPROM_READ_OS_DONE:
184 bleCommandState = FIRMWARE_DOWNLOAD__DONE;
185 [self bleCommandTask];
186 break;
187 case FIRMWARE_DOWNLOAD__DONE:
188 {
189 NSLog(@"Ble command set done!");
190 [self getDownloadList];
191 break;
192 }
193 }
194 return false;
195 }
196
197 - (void)protocolDidGetData:(NSString *)dataType data:(NSString *)dataData {
198 if([dataType isEqualToString:@"infoDeviceId"]) {
199 NSLog(@"infoDeviceId");
200 strId = dataData;
201 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_ID_DONE;
202 [self bleCommandTask];
203 } else if([dataType isEqualToString:@"infoDeviceModel"]) {
204 NSLog(@"infoDeviceModel");
205 strModel = dataData;
206 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_MODEL_DONE;
207 [self bleCommandTask];
208 } else if([dataType isEqualToString:@"infoDeviceType"]) {
209 NSLog(@"infoDeviceType");
210 strType = dataData;
211 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_TYPE_DONE;
212 [self bleCommandTask];
213 } else if([dataType isEqualToString:@"infoDeviceOs"]) {
214 NSLog(@"infoDeviceOs");
215 strOs = dataData;
216 bleCommandState = FIRMWARE_DOWNLOAD__EEPROM_READ_OS_DONE;
217 [self bleCommandTask];
218 }
219 }
220
221 /*
222 #pragma mark - Navigation
223
224 // In a storyboard-based application, you will often want to do a little preparation before navigation
225 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
226 // Get the new view controller using [segue destinationViewController].
227 // Pass the selected object to the new view controller.
228 }
229 */
230
231 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
8 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 </dependencies>
10 <objects>
11 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FirmwareDownloadController">
12 <connections>
13 <outlet property="lblPercentComplete" destination="Mjh-27-eGB" id="13E-30-jj7"/>
14 <outlet property="tblFirmware" destination="erf-sK-RX7" id="tcE-GL-fEf"/>
15 <outlet property="view" destination="xbi-n3-MOM" id="qjE-58-VqO"/>
16 </connections>
17 </placeholder>
18 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
19 <view contentMode="scaleToFill" id="xbi-n3-MOM">
20 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22 <subviews>
23 <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="erf-sK-RX7">
24 <rect key="frame" x="0.0" y="114" width="375" height="553"/>
25 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
26 </tableView>
27 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Oce-KB-tk0">
28 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
29 <items>
30 <navigationItem title="ファームウェアDL" id="iQA-Ru-iNE">
31 <barButtonItem key="leftBarButtonItem" title="戻る" id="feZ-vp-UB8">
32 <connections>
33 <action selector="cancelButtonClicked:" destination="-1" id="BbS-7p-KWV"/>
34 </connections>
35 </barButtonItem>
36 </navigationItem>
37 </items>
38 </navigationBar>
39 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mjh-27-eGB">
40 <rect key="frame" x="0.0" y="85" width="375" height="21"/>
41 <constraints>
42 <constraint firstAttribute="height" constant="21" id="sgi-RD-ywG"/>
43 </constraints>
44 <fontDescription key="fontDescription" type="system" pointSize="17"/>
45 <nil key="textColor"/>
46 <nil key="highlightedColor"/>
47 </label>
48 </subviews>
49 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
50 <constraints>
51 <constraint firstItem="erf-sK-RX7" firstAttribute="trailing" secondItem="Mjh-27-eGB" secondAttribute="trailing" id="8cr-0D-Wsn"/>
52 <constraint firstItem="Mjh-27-eGB" firstAttribute="top" secondItem="Oce-KB-tk0" secondAttribute="bottom" constant="18" id="ChU-4v-QTf"/>
53 <constraint firstItem="erf-sK-RX7" firstAttribute="top" secondItem="Mjh-27-eGB" secondAttribute="bottom" constant="8" symbolic="YES" id="F4t-w2-3Ki"/>
54 <constraint firstItem="erf-sK-RX7" firstAttribute="leading" secondItem="Mjh-27-eGB" secondAttribute="leading" id="JEl-P9-VO6"/>
55 <constraint firstAttribute="trailing" secondItem="erf-sK-RX7" secondAttribute="trailing" id="KGd-4x-ijs"/>
56 <constraint firstAttribute="bottom" secondItem="erf-sK-RX7" secondAttribute="bottom" id="Kyb-Se-oRR"/>
57 <constraint firstItem="Oce-KB-tk0" firstAttribute="top" secondItem="xbi-n3-MOM" secondAttribute="top" constant="23" id="WZ0-1l-eIW"/>
58 <constraint firstItem="Oce-KB-tk0" firstAttribute="trailing" secondItem="Mjh-27-eGB" secondAttribute="trailing" id="bVM-cw-kfp"/>
59 <constraint firstItem="erf-sK-RX7" firstAttribute="leading" secondItem="xbi-n3-MOM" secondAttribute="leading" id="fXw-QY-PLy"/>
60 <constraint firstItem="Oce-KB-tk0" firstAttribute="leading" secondItem="Mjh-27-eGB" secondAttribute="leading" id="zmz-jd-CrP"/>
61 </constraints>
62 <point key="canvasLocation" x="-203.5" y="147.5"/>
63 </view>
64 </objects>
65 </document>
1 //
2 // FirmwareDownloadControllerTableViewCell.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @interface FirmwareDownloadControllerTableViewCell : UITableViewCell
12
13 @property (strong, nonatomic) IBOutlet UILabel *lblTitle;
14 @property (strong, nonatomic) IBOutlet UILabel *lblSubtitle;
15
16 @end
1 //
2 // FirmwareDownloadControllerTableCellTableViewCell.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "FirmwareDownloadControllerTableViewCell.h"
10
11 @implementation FirmwareDownloadControllerTableViewCell
12
13 - (void)awakeFromNib {
14 [super awakeFromNib];
15 // Initialization code
16 }
17
18 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 [super setSelected:selected animated:animated];
20
21 // Configure the view for the selected state
22 }
23
24 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
8 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14 <tableViewCell contentMode="scaleToFill" restorationIdentifier="mycell" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" userLabel="Firmware Download Controller Table View Cell" customClass="FirmwareDownloadControllerTableViewCell">
15 <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
16 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
17 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
18 <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
19 <autoresizingMask key="autoresizingMask"/>
20 <subviews>
21 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="サブタイトル" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FUj-Q3-Rtz">
22 <rect key="frame" x="17" y="22" width="303" height="21"/>
23 <fontDescription key="fontDescription" type="system" pointSize="12"/>
24 <nil key="textColor"/>
25 <nil key="highlightedColor"/>
26 </label>
27 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="タイトル" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mMs-ai-Esq">
28 <rect key="frame" x="17" y="4" width="303" height="21"/>
29 <fontDescription key="fontDescription" type="system" pointSize="17"/>
30 <nil key="textColor"/>
31 <nil key="highlightedColor"/>
32 </label>
33 </subviews>
34 <constraints>
35 <constraint firstItem="FUj-Q3-Rtz" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="14" id="Ifu-3l-cZ2"/>
36 <constraint firstItem="FUj-Q3-Rtz" firstAttribute="leading" secondItem="mMs-ai-Esq" secondAttribute="leading" id="OZM-Dl-ddG"/>
37 <constraint firstItem="mMs-ai-Esq" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="-4" id="bey-do-AaT"/>
38 <constraint firstAttribute="bottomMargin" secondItem="FUj-Q3-Rtz" secondAttribute="bottom" constant="-7.5" id="hL8-P8-yuW"/>
39 <constraint firstItem="mMs-ai-Esq" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="9" id="kHc-HS-oAw"/>
40 <constraint firstItem="FUj-Q3-Rtz" firstAttribute="trailing" secondItem="mMs-ai-Esq" secondAttribute="trailing" id="sWv-je-ezI"/>
41 <constraint firstAttribute="trailing" secondItem="mMs-ai-Esq" secondAttribute="trailing" id="tab-yq-GfI"/>
42 </constraints>
43 </tableViewCellContentView>
44 <connections>
45 <outlet property="lblSubtitle" destination="FUj-Q3-Rtz" id="y7i-UH-MNh"/>
46 <outlet property="lblTitle" destination="mMs-ai-Esq" id="ODY-6M-Ul5"/>
47 </connections>
48 </tableViewCell>
49 </objects>
50 </document>
1 //
2 // FirmwareUpdateController.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/05.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12
13 typedef enum {
14 MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF,
15 MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF_DONE,
16 MODE_FIRMWARE_IMAGE_SELECT_0_RESET_IN_BOOTLOADER,
17 MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF,
18 MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF_DONE,
19 MODE_FIRMWARE_IMAGE_SELECT_1,
20 MODE_FIRMWARE_IMAGE_SELECT_1_DONE,
21 MODE_FIRMWARE_IMAGE_SELECT_1_RESET,
22 } ModeFirmwareUpdateState;
23
24 @interface FirmwareUpdateController : UIViewController <BLEProtocolDelegate> {
25 ModeFirmwareUpdateState firmwareUpdateState;
26 }
27
28 @property (strong, nonatomic) IBOutlet UILabel *lblStateDownload;
29 @property (strong, nonatomic) IBOutlet UILabel *lblStateMCUWrite;
30
31 @property (strong, nonatomic) BleProtocol *protocol;
32 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
33
34 @end
1 //
2 // FirmwareUpdateController.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/05.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "FirmwareUpdateController.h"
10 #import "FirmwareWriteController.h"
11
12 @interface FirmwareUpdateController ()
13
14 @end
15
16 @implementation FirmwareUpdateController
17
18 - (void)viewDidLoad {
19 [super viewDidLoad];
20 // Do any additional setup after loading the view.
21 }
22
23 - (void)viewWillAppear:(BOOL)animated {
24 self.lastProtocolDelegate = self.protocol.delegate;
25 self.protocol.delegate = self;
26 }
27
28 - (void)viewWillDisappear:(BOOL)animated {
29 self.protocol.delegate = self.lastProtocolDelegate;
30 }
31
32 - (void)didReceiveMemoryWarning {
33 [super didReceiveMemoryWarning];
34 // Dispose of any resources that can be recreated.
35 }
36
37 /*
38 #pragma mark - Navigation
39
40 // In a storyboard-based application, you will often want to do a little preparation before navigation
41 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
42 // Get the new view controller using [segue destinationViewController].
43 // Pass the selected object to the new view controller.
44 }
45 */
46
47 - (IBAction)modeBootloaderButtonClicked:(id)sender {
48 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF;
49 [self firmwareWriteTask];
50 }
51
52 - (IBAction)modeImage1ButtonClicked:(id)sender {
53 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF;
54 [self firmwareWriteTask];
55 }
56
57 - (IBAction)cancelButtonClicked:(id)sender {
58 [self dismissViewControllerAnimated:YES completion:Nil];
59 }
60
61 - (IBAction)mcuWriteButtonClicked:(id)sender {
62 FirmwareWriteController *viewObj=[[FirmwareWriteController alloc] initWithNibName:@"FirmwareWriteController" bundle:nil];
63 viewObj.protocol = self.protocol;
64 [self presentViewController:viewObj animated:YES completion: nil];
65 }
66
67 - (void)protocolDidGetData:(NSString *)dataType data:(NSString *)dataData {
68 if([dataType isEqualToString:@"firmwareImageSelect"]) {
69 if([dataData isEqualToString: @"0"]) {
70 [[self protocol]putData:@"systemReset" data:nil];
71 } else if([dataData isEqualToString: @"1"]) {
72 [[self protocol]putData:@"systemReset" data:nil];
73 }
74 } else if([dataType isEqualToString:@"eepromWriteProtect"]) {
75 if([dataData isEqualToString:@"0"]) {
76 NSLog(@"firmwareImageSelect 0");
77 switch(firmwareUpdateState) {
78 case MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF:
79 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF_DONE;
80 break;
81 case MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF:
82 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF_DONE;
83 break;
84 default:
85 break;
86 }
87 [self firmwareWriteTask];
88 }
89 }
90 }
91
92 - (void)firmwareWriteTask {
93 switch(firmwareUpdateState) {
94 case MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF:
95 [[self protocol]putData:@"eepromWriteProtect" data:@"0"];
96 break;
97 case MODE_FIRMWARE_IMAGE_SELECT_0_EEPROM_WP_OFF_DONE:
98 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_0_RESET_IN_BOOTLOADER;
99 [self firmwareWriteTask];
100 break;
101 case MODE_FIRMWARE_IMAGE_SELECT_0_RESET_IN_BOOTLOADER:
102 [[self protocol]putData:@"systemResetInBootloader" data:nil];
103 break;
104 case MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF:
105 [[self protocol]putData:@"eepromWriteProtect" data:@"0"];
106 break;
107 case MODE_FIRMWARE_IMAGE_SELECT_1_EEPROM_WP_OFF_DONE:
108 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_1;
109 [self firmwareWriteTask];
110 break;
111 case MODE_FIRMWARE_IMAGE_SELECT_1:
112 [[self protocol]putData:@"firmwareImageSelect" data:@"1"];
113 break;
114 case MODE_FIRMWARE_IMAGE_SELECT_1_DONE:
115 firmwareUpdateState = MODE_FIRMWARE_IMAGE_SELECT_1_RESET;
116 [self firmwareWriteTask];
117 break;
118 case MODE_FIRMWARE_IMAGE_SELECT_1_RESET:
119 [[self protocol]putData:@"systemReset" data:nil];
120 break;
121 }
122 }
123
124 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <deployment identifier="iOS"/>
8 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FirmwareUpdateController">
13 <connections>
14 <outlet property="lblStateMCUWrite" destination="4iS-Ml-6zs" id="O5y-do-L3o"/>
15 <outlet property="view" destination="Dee-Uj-9dH" id="pHd-FJ-YjS"/>
16 </connections>
17 </placeholder>
18 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
19 <view contentMode="scaleToFill" id="Dee-Uj-9dH">
20 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22 <subviews>
23 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FCe-34-Low">
24 <rect key="frame" x="118" y="165" width="138" height="30"/>
25 <state key="normal" title="選択して書込み開始"/>
26 <connections>
27 <action selector="mcuWriteButtonClicked:" destination="-1" eventType="touchUpInside" id="mav-u1-ZQe"/>
28 </connections>
29 </button>
30 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="書き込み:なし" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4iS-Ml-6zs">
31 <rect key="frame" x="126" y="111" width="122" height="21"/>
32 <fontDescription key="fontDescription" type="system" pointSize="17"/>
33 <nil key="textColor"/>
34 <nil key="highlightedColor"/>
35 </label>
36 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="SZv-OE-aWd">
37 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
38 <items>
39 <navigationItem title="ファームウェア更新" id="uhQ-pe-SM8">
40 <barButtonItem key="leftBarButtonItem" title="戻る" id="48U-xg-bRO">
41 <connections>
42 <action selector="cancelButtonClicked:" destination="-1" id="fys-Tk-uSB"/>
43 </connections>
44 </barButtonItem>
45 </navigationItem>
46 </items>
47 </navigationBar>
48 </subviews>
49 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
50 <constraints>
51 <constraint firstItem="4iS-Ml-6zs" firstAttribute="top" secondItem="SZv-OE-aWd" secondAttribute="bottom" constant="44" id="8bo-uQ-mYp"/>
52 <constraint firstItem="FCe-34-Low" firstAttribute="top" secondItem="4iS-Ml-6zs" secondAttribute="bottom" constant="33" id="9dJ-NV-aIu"/>
53 <constraint firstItem="4iS-Ml-6zs" firstAttribute="centerX" secondItem="FCe-34-Low" secondAttribute="centerX" id="Lt9-oI-Js3"/>
54 <constraint firstAttribute="trailing" secondItem="SZv-OE-aWd" secondAttribute="trailing" id="PHa-jh-RdD"/>
55 <constraint firstItem="4iS-Ml-6zs" firstAttribute="centerX" secondItem="SZv-OE-aWd" secondAttribute="centerX" id="ZFH-JH-KIM"/>
56 <constraint firstItem="SZv-OE-aWd" firstAttribute="top" secondItem="Dee-Uj-9dH" secondAttribute="top" constant="23" id="ak4-yS-Orr"/>
57 <constraint firstItem="SZv-OE-aWd" firstAttribute="leading" secondItem="Dee-Uj-9dH" secondAttribute="leading" id="nZt-Jg-g8l"/>
58 </constraints>
59 <point key="canvasLocation" x="21.5" y="-37.5"/>
60 </view>
61 </objects>
62 </document>
1 //
2 // FirmwareWriteController.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12 #import <QuartzCore/QuartzCore.h>
13
14 typedef enum {
15 ERASE_PAGE_1,
16 UPLOAD_PAGE_10_ERASE_TEMP,
17 UPLOAD_PAGE_10_BEGIN,
18 UPLOAD_PAGE_10_CONTINUE,
19 UPLOAD_PAGE_10_RETRY,
20 UPLOAD_PAGE_10_END,
21 WRITE_PAGE_10,
22 WRITE_PAGE_10_DONE,
23 UPLOAD_PAGE_11_ERASE_TEMP,
24 UPLOAD_PAGE_11_BEGIN,
25 UPLOAD_PAGE_11_CONTINUE,
26 UPLOAD_PAGE_11_RETRY,
27 UPLOAD_PAGE_11_END,
28 WRITE_PAGE_11,
29 WRITE_PAGE_11_DONE,
30 UPLOAD_PAGE_12_ERASE_TEMP,
31 UPLOAD_PAGE_12_BEGIN,
32 UPLOAD_PAGE_12_CONTINUE,
33 UPLOAD_PAGE_12_RETRY,
34 UPLOAD_PAGE_12_END,
35 WRITE_PAGE_12,
36 WRITE_PAGE_12_DONE,
37 UPLOAD_PAGE_13_ERASE_TEMP,
38 UPLOAD_PAGE_13_BEGIN,
39 UPLOAD_PAGE_13_CONTINUE,
40 UPLOAD_PAGE_13_RETRY,
41 UPLOAD_PAGE_13_END,
42 WRITE_PAGE_13,
43 WRITE_PAGE_13_DONE,
44 UPLOAD_DONE,
45 EEPROM_WP_OFF,
46 EEPROM_WP_OFF_DONE,
47 FIRMWARE_IMAGE_SELECT_1,
48 FIRMWARE_IMAGE_SELECT_1_DONE,
49 RESET,
50 RESET_DONE
51 } FirmwareUpdateState;
52
53 @interface FirmwareWriteController : UIViewController<UITableViewDelegate, UITableViewDataSource, BLEProtocolDelegate> {
54
55 IBOutlet UITableView *tblFirmware;
56 IBOutlet UILabel *lblPercentComplete;
57 NSMutableArray *arrResult;
58 int selectionEnabled;
59 NSInputStream *firmwareFileStream;
60 unsigned long long firmwareFileStreamSize;
61 unsigned long long firmwareFileStreamPointer;
62 NSData *firmwareWriteBuffer;
63 int firmwareWriteBufferRetry;
64 FirmwareUpdateState firmwareUpdateState;
65 unsigned long long firmwareFlashPagePointer;
66 CFTimeInterval startTime;
67 }
68
69 @property (strong, nonatomic) BleProtocol *protocol;
70 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
71
72 - (BOOL)firmwareWriteTask;
73
74 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
8 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 </dependencies>
10 <objects>
11 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FirmwareWriteController">
12 <connections>
13 <outlet property="lblPercentComplete" destination="gbe-O8-4MZ" id="tzg-Iq-QuD"/>
14 <outlet property="tblFirmware" destination="Bm4-3e-kcl" id="MoB-u5-JGI"/>
15 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
16 </connections>
17 </placeholder>
18 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
19 <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
20 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
22 <subviews>
23 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="GD6-XB-ga1">
24 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
25 <items>
26 <navigationItem title="ファームウェア書き込み" id="M6c-ur-fNv">
27 <barButtonItem key="leftBarButtonItem" title="戻る" id="vHb-pY-nI8">
28 <connections>
29 <action selector="cancelButtonClicked:" destination="-1" id="PP3-RL-PMI"/>
30 </connections>
31 </barButtonItem>
32 </navigationItem>
33 </items>
34 </navigationBar>
35 <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Bm4-3e-kcl">
36 <rect key="frame" x="0.0" y="114" width="375" height="553"/>
37 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
38 </tableView>
39 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gbe-O8-4MZ">
40 <rect key="frame" x="0.0" y="85" width="375" height="21"/>
41 <constraints>
42 <constraint firstAttribute="height" constant="21" id="EGb-VE-YbS"/>
43 </constraints>
44 <fontDescription key="fontDescription" type="system" pointSize="17"/>
45 <nil key="textColor"/>
46 <nil key="highlightedColor"/>
47 </label>
48 </subviews>
49 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
50 <constraints>
51 <constraint firstItem="Bm4-3e-kcl" firstAttribute="trailing" secondItem="gbe-O8-4MZ" secondAttribute="trailing" id="Abo-tT-Thu"/>
52 <constraint firstItem="GD6-XB-ga1" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="FtV-kf-WI3"/>
53 <constraint firstItem="gbe-O8-4MZ" firstAttribute="top" secondItem="GD6-XB-ga1" secondAttribute="bottom" constant="18" id="GoQ-Q5-91K"/>
54 <constraint firstItem="Bm4-3e-kcl" firstAttribute="top" secondItem="gbe-O8-4MZ" secondAttribute="bottom" constant="8" symbolic="YES" id="Une-zo-zte"/>
55 <constraint firstItem="gbe-O8-4MZ" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="fxk-Ov-pU5"/>
56 <constraint firstItem="Bm4-3e-kcl" firstAttribute="leading" secondItem="gbe-O8-4MZ" secondAttribute="leading" id="gbQ-tt-xdK"/>
57 <constraint firstAttribute="trailing" secondItem="GD6-XB-ga1" secondAttribute="trailing" id="jWA-Pb-qcK"/>
58 <constraint firstAttribute="trailing" secondItem="gbe-O8-4MZ" secondAttribute="trailing" id="qg6-AW-Ney"/>
59 <constraint firstAttribute="bottom" secondItem="Bm4-3e-kcl" secondAttribute="bottom" id="u5Z-t5-eje"/>
60 <constraint firstItem="GD6-XB-ga1" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="23" id="zUz-9r-bi8"/>
61 </constraints>
62 <point key="canvasLocation" x="24.5" y="52.5"/>
63 </view>
64 </objects>
65 </document>
1 //
2 // FirmwareWriteControllerTableViewCell.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/07.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @interface FirmwareWriteControllerTableViewCell : UITableViewCell
12
13 @property (strong, nonatomic) IBOutlet UILabel *lblTitle;
14 @property (strong, nonatomic) IBOutlet UILabel *lblSubtitle;
15
16 @end
1 //
2 // FirmwareWriteControllerTableViewCell.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/07.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "FirmwareWriteControllerTableViewCell.h"
10
11 @implementation FirmwareWriteControllerTableViewCell
12
13 - (void)awakeFromNib {
14 [super awakeFromNib];
15 // Initialization code
16 }
17
18 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 [super setSelected:selected animated:animated];
20
21 // Configure the view for the selected state
22 }
23
24 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
8 <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14 <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="FirmwareWriteControllerTableViewCell">
15 <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
16 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
17 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
18 <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
19 <autoresizingMask key="autoresizingMask"/>
20 <subviews>
21 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="タイトル" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hee-i7-oLg">
22 <rect key="frame" x="17" y="4" width="303" height="21"/>
23 <fontDescription key="fontDescription" type="system" pointSize="17"/>
24 <nil key="textColor"/>
25 <nil key="highlightedColor"/>
26 </label>
27 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="サブタイトル" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XEF-Tk-t7H">
28 <rect key="frame" x="17" y="22" width="303" height="21"/>
29 <fontDescription key="fontDescription" type="system" pointSize="12"/>
30 <nil key="textColor"/>
31 <nil key="highlightedColor"/>
32 </label>
33 </subviews>
34 <constraints>
35 <constraint firstItem="XEF-Tk-t7H" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="14" id="4fz-2b-2iR"/>
36 <constraint firstAttribute="trailing" secondItem="hee-i7-oLg" secondAttribute="trailing" id="FPe-q7-Kt0"/>
37 <constraint firstItem="hee-i7-oLg" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" constant="9" id="LWf-z4-6OC"/>
38 <constraint firstItem="hee-i7-oLg" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="-4" id="aU2-zO-01S"/>
39 <constraint firstItem="hee-i7-oLg" firstAttribute="trailing" secondItem="XEF-Tk-t7H" secondAttribute="trailing" id="onp-HC-6zn"/>
40 <constraint firstItem="hee-i7-oLg" firstAttribute="leading" secondItem="XEF-Tk-t7H" secondAttribute="leading" id="wGx-O2-PWb"/>
41 <constraint firstAttribute="bottomMargin" secondItem="XEF-Tk-t7H" secondAttribute="bottom" constant="-7.5" id="yYM-VE-A2L"/>
42 </constraints>
43 </tableViewCellContentView>
44 <connections>
45 <outlet property="lblSubtitle" destination="XEF-Tk-t7H" id="6ub-Gh-yfi"/>
46 <outlet property="lblTitle" destination="hee-i7-oLg" id="Exz-fq-eqY"/>
47 </connections>
48 </tableViewCell>
49 </objects>
50 </document>
1 //
2 // InputMotorController.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/02/23.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12
13 @interface InputMotorController : UIViewController <BLEProtocolDelegate>
14
15 @property (nonatomic, strong) NSString *jacketId;
16 @property (strong, nonatomic) BleProtocol *protocol;
17 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
18
19 @end
1 //
2 // InputMotorController.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/02/23.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "InputMotorController.h"
10
11 @interface InputMotorController ()
12 @property (strong, nonatomic) IBOutlet UIButton *btn0;
13 @property (strong, nonatomic) IBOutlet UIButton *btn1;
14 @property (strong, nonatomic) IBOutlet UIButton *btn2;
15
16 @end
17
18 @implementation InputMotorController {
19 UIView *_mask;
20 NSTimer *_writeResponseTimer;
21 bool ignoreWriteResponse;
22 id lastButton;
23 NSInteger newState;
24 }
25 @synthesize protocol;
26
27 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
28 [_mask removeFromSuperview];
29 [self dismissViewControllerAnimated:YES completion:Nil];
30 }
31
32 - (void)viewWillAppear:(BOOL)animated {
33 [super viewWillAppear:animated];
34 _lastProtocolDelegate = protocol.delegate;
35 protocol.delegate = self;
36 }
37
38 - (void)viewWillDisappear:(BOOL)animated {
39 [super viewWillDisappear:animated];
40 protocol.delegate = _lastProtocolDelegate;
41 }
42
43 - (void)viewDidLoad {
44 [super viewDidLoad];
45 // Do any additional setup after loading the view from its nib.
46 }
47
48 - (void)didReceiveMemoryWarning {
49 [super didReceiveMemoryWarning];
50 // Dispose of any resources that can be recreated.
51 }
52
53 /*
54 #pragma mark - Navigation
55
56 // In a storyboard-based application, you will often want to do a little preparation before navigation
57 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
58 // Get the new view controller using [segue destinationViewController].
59 // Pass the selected object to the new view controller.
60 }
61 */
62 - (void)showAlert {
63 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ジャケットの設定"
64 message:@"設定が保存されました。"
65 delegate:self
66 cancelButtonTitle:@"OK"
67 otherButtonTitles:nil];
68 [alert show];
69 }
70
71 - (void)showAlert:(NSString*)title message:(NSString*)message{
72 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
73 message:message
74 delegate:self
75 cancelButtonTitle:@"OK"
76 otherButtonTitles:nil];
77 [alert show];
78 }
79
80 - (void)showMask {
81 _mask = [[UIView alloc] initWithFrame:[self.view frame]];
82 [_mask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.25]];
83 [self.view addSubview:_mask];
84 }
85
86 -(void)writeResponseTimeout:(NSTimer *)timer {
87 ignoreWriteResponse = true;
88 [self showAlert:@"ジャケットの設定" message:@"設定が保存されない。"];
89 }
90
91 - (void)protocolDidGetData:(NSString *)dataType data:(NSString *)dataData {
92 if([dataType isEqualToString:@"writeMotor"]){
93 if(ignoreWriteResponse) return;
94 [_writeResponseTimer invalidate];
95
96 if([dataData isEqual:@"OK"]) {
97 [self showAlert:@"ジャケットの設定" message:@"設定が保存されました。"];
98 } else {
99 [self showAlert:@"ジャケットの設定" message:@"設定が保存されない。"];
100 }
101 }
102 }
103
104 - (IBAction)btn0:(id)sender {
105 if(lastButton) {
106 [lastButton setBackgroundColor:[UIColor clearColor]];
107 }
108 lastButton = sender;
109 newState = 0;
110 [sender setBackgroundColor:[UIColor yellowColor]];
111 }
112
113 - (IBAction)btn1:(id)sender {
114 if(lastButton) {
115 [lastButton setBackgroundColor:[UIColor clearColor]];
116 }
117 lastButton = sender;
118 newState = 1;
119 [sender setBackgroundColor:[UIColor yellowColor]];
120 }
121
122 - (IBAction)btn2:(id)sender {
123 if(lastButton) {
124 [lastButton setBackgroundColor:[UIColor clearColor]];
125 }
126 lastButton = sender;
127 newState = 2;
128 [sender setBackgroundColor:[UIColor yellowColor]];
129 }
130
131 - (IBAction)cancelButtonClicked:(id)sender {
132 [self dismissViewControllerAnimated:YES completion:Nil];
133 }
134
135 - (IBAction)saveButtonClicked:(id)sender {
136 ignoreWriteResponse = false;
137 [self showMask];
138 [protocol putData:@"writeMotor" data:[NSString stringWithFormat:@"%ld",newState]];
139 _writeResponseTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self selector:@selector(writeResponseTimeout:) userInfo: nil repeats:NO];
140 }
141
142 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <deployment identifier="iOS"/>
8 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="InputMotorController">
13 <connections>
14 <outlet property="btn0" destination="y6L-Z8-PBp" id="0If-yX-pUs"/>
15 <outlet property="btn1" destination="N8B-HG-KJu" id="Qjf-65-PYn"/>
16 <outlet property="btn2" destination="YiN-Ek-vti" id="Fng-yV-kXC"/>
17 <outlet property="view" destination="9aV-RW-OZ8" id="LHe-HA-LNf"/>
18 </connections>
19 </placeholder>
20 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
21 <view contentMode="scaleToFill" id="9aV-RW-OZ8">
22 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
23 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
24 <subviews>
25 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="y6L-Z8-PBp">
26 <rect key="frame" x="172" y="97" width="30" height="30"/>
27 <state key="normal" title="OFF"/>
28 <connections>
29 <action selector="btn0:" destination="-2" eventType="touchUpInside" id="ASw-mk-2I6"/>
30 <action selector="btn0:" destination="-1" eventType="touchUpInside" id="eTs-nj-jCz"/>
31 </connections>
32 </button>
33 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="N8B-HG-KJu">
34 <rect key="frame" x="89" y="157" width="197" height="30"/>
35 <state key="normal" title="ON 0 (iOSホームボタン押し)"/>
36 <connections>
37 <action selector="btn1:" destination="-2" eventType="touchUpInside" id="VWj-L6-FAy"/>
38 <action selector="btn1:" destination="-1" eventType="touchUpInside" id="i5s-rG-fdC"/>
39 </connections>
40 </button>
41 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8X3-1K-oyZ">
42 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
43 <items>
44 <navigationItem title="モーターの設定" id="JpB-f0-A8S">
45 <barButtonItem key="leftBarButtonItem" title="戻る" id="QfV-3b-uNb">
46 <connections>
47 <action selector="cancelButtonClicked:" destination="-1" id="kSA-tc-wgg"/>
48 </connections>
49 </barButtonItem>
50 <barButtonItem key="rightBarButtonItem" title="保存" id="Jvg-is-ZAy">
51 <connections>
52 <action selector="saveButtonClicked:" destination="-1" id="xkU-dg-36I"/>
53 </connections>
54 </barButtonItem>
55 </navigationItem>
56 </items>
57 </navigationBar>
58 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YiN-Ek-vti">
59 <rect key="frame" x="61" y="217" width="253" height="30"/>
60 <state key="normal" title="ON 1(ANDRIODホームボタン押し)"/>
61 <connections>
62 <action selector="btn2:" destination="-1" eventType="touchUpInside" id="avV-Oc-oJQ"/>
63 <action selector="btn2:" destination="-2" eventType="touchUpInside" id="yzK-gg-Icl"/>
64 </connections>
65 </button>
66 </subviews>
67 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
68 <constraints>
69 <constraint firstItem="y6L-Z8-PBp" firstAttribute="top" secondItem="8X3-1K-oyZ" secondAttribute="bottom" constant="30" id="1IP-9d-ZtC"/>
70 <constraint firstItem="N8B-HG-KJu" firstAttribute="top" secondItem="y6L-Z8-PBp" secondAttribute="bottom" constant="30" id="ExD-uU-gJa"/>
71 <constraint firstItem="8X3-1K-oyZ" firstAttribute="centerX" secondItem="y6L-Z8-PBp" secondAttribute="centerX" id="JPi-Xc-I0P"/>
72 <constraint firstItem="YiN-Ek-vti" firstAttribute="top" secondItem="N8B-HG-KJu" secondAttribute="bottom" constant="30" id="O9g-kB-Qwr"/>
73 <constraint firstItem="y6L-Z8-PBp" firstAttribute="top" secondItem="8X3-1K-oyZ" secondAttribute="bottom" constant="30" id="ZmM-NH-pzR"/>
74 <constraint firstItem="N8B-HG-KJu" firstAttribute="centerX" secondItem="9aV-RW-OZ8" secondAttribute="centerX" id="apJ-QU-yP3"/>
75 <constraint firstItem="8X3-1K-oyZ" firstAttribute="top" secondItem="9aV-RW-OZ8" secondAttribute="top" constant="23" id="hqq-Uz-88D"/>
76 <constraint firstItem="YiN-Ek-vti" firstAttribute="centerX" secondItem="9aV-RW-OZ8" secondAttribute="centerX" id="kg8-xM-aVZ"/>
77 <constraint firstAttribute="trailing" secondItem="8X3-1K-oyZ" secondAttribute="trailing" id="lb2-Nl-Lmt"/>
78 <constraint firstItem="8X3-1K-oyZ" firstAttribute="leading" secondItem="9aV-RW-OZ8" secondAttribute="leading" id="xcc-yg-Zzi"/>
79 <constraint firstItem="y6L-Z8-PBp" firstAttribute="centerX" secondItem="9aV-RW-OZ8" secondAttribute="centerX" id="z3G-w1-vpt"/>
80 </constraints>
81 <point key="canvasLocation" x="-67" y="-73"/>
82 </view>
83 </objects>
84 </document>
1 //
2 // InputSoundController.h
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/10/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12
13 @interface InputSoundController : UIViewController <BLEProtocolDelegate>
14
15 @property (nonatomic, strong) NSString *jacketId;
16 @property (strong, nonatomic) BleProtocol *protocol;
17 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
18
19 @end
1 //
2 // InputSoundController.m
3 // jacket_test_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/10/06.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "InputSoundController.h"
10
11 @interface InputSoundController ()
12 @property (strong, nonatomic) IBOutlet UIButton *btn0;
13 @property (strong, nonatomic) IBOutlet UIButton *btn1;
14
15 @end
16
17 @implementation InputSoundController {
18 UIView *_mask;
19 NSTimer *_writeResponseTimer;
20 bool ignoreWriteResponse;
21 id lastButton;
22 NSInteger newState;
23 }
24 @synthesize protocol;
25
26 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
27 [_mask removeFromSuperview];
28 [self dismissViewControllerAnimated:YES completion:Nil];
29 }
30
31 - (void)viewWillAppear:(BOOL)animated {
32 [super viewWillAppear:animated];
33 _lastProtocolDelegate = protocol.delegate;
34 protocol.delegate = self;
35 }
36
37 - (void)viewWillDisappear:(BOOL)animated {
38 [super viewWillDisappear:animated];
39 protocol.delegate = _lastProtocolDelegate;
40 }
41
42 - (void)viewDidLoad {
43 [super viewDidLoad];
44 // Do any additional setup after loading the view from its nib.
45 }
46
47 - (void)didReceiveMemoryWarning {
48 [super didReceiveMemoryWarning];
49 // Dispose of any resources that can be recreated.
50 }
51
52 /*
53 #pragma mark - Navigation
54
55 // In a storyboard-based application, you will often want to do a little preparation before navigation
56 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
57 // Get the new view controller using [segue destinationViewController].
58 // Pass the selected object to the new view controller.
59 }
60 */
61 - (void)showAlert {
62 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ジャケットの設定"
63 message:@"設定が保存されました。"
64 delegate:self
65 cancelButtonTitle:@"OK"
66 otherButtonTitles:nil];
67 [alert show];
68 }
69
70 - (void)showAlert:(NSString*)title message:(NSString*)message{
71 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
72 message:message
73 delegate:self
74 cancelButtonTitle:@"OK"
75 otherButtonTitles:nil];
76 [alert show];
77 }
78
79 - (void)showMask {
80 _mask = [[UIView alloc] initWithFrame:[self.view frame]];
81 [_mask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.25]];
82 [self.view addSubview:_mask];
83 }
84
85 -(void)writeResponseTimeout:(NSTimer *)timer {
86 ignoreWriteResponse = true;
87 [self showAlert:@"ジャケットの設定" message:@"設定が保存されない。"];
88 }
89
90 - (void)protocolDidGetData:(NSString *)dataType data:(NSString *)dataData {
91 if([dataType isEqualToString:@"writeSound"]){
92 if(ignoreWriteResponse) return;
93 [_writeResponseTimer invalidate];
94
95 if([dataData isEqual:@"OK"]) {
96 [self showAlert:@"ジャケットの設定" message:@"設定が保存されました。"];
97 } else {
98 [self showAlert:@"ジャケットの設定" message:@"設定が保存されない。"];
99 }
100 }
101 }
102
103 - (IBAction)btn0:(id)sender {
104 if(lastButton) {
105 [lastButton setBackgroundColor:[UIColor clearColor]];
106 }
107 lastButton = sender;
108 newState = 0;
109 [sender setBackgroundColor:[UIColor yellowColor]];
110 }
111
112 - (IBAction)btn1:(id)sender {
113 if(lastButton) {
114 [lastButton setBackgroundColor:[UIColor clearColor]];
115 }
116 lastButton = sender;
117 newState = 1;
118 [sender setBackgroundColor:[UIColor yellowColor]];
119 }
120
121 - (IBAction)cancelButtonClicked:(id)sender {
122 [self dismissViewControllerAnimated:YES completion:Nil];
123 }
124
125 - (IBAction)saveButtonClicked:(id)sender {
126 ignoreWriteResponse = false;
127 [self showMask];
128 [protocol putData:@"writeSound" data:[NSString stringWithFormat:@"%ld",newState]];
129 _writeResponseTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self selector:@selector(writeResponseTimeout:) userInfo: nil repeats:NO];
130 }
131
132 @end
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <deployment identifier="iOS"/>
8 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
9 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10 </dependencies>
11 <objects>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="InputSoundController">
13 <connections>
14 <outlet property="btn0" destination="PpR-jP-zBp" id="3vy-Dd-cfz"/>
15 <outlet property="btn1" destination="AoY-L8-av3" id="XJd-q4-Hsz"/>
16 <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
17 </connections>
18 </placeholder>
19 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
20 <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
21 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
22 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23 <subviews>
24 <navigationBar contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MGO-KK-hkK">
25 <rect key="frame" x="0.0" y="23" width="375" height="44"/>
26 <items>
27 <navigationItem title="サウンドの設定" id="3l5-OJ-hVk">
28 <barButtonItem key="leftBarButtonItem" title="戻る" id="aaD-A8-qxu">
29 <connections>
30 <action selector="cancelButtonClicked:" destination="-1" id="92j-lv-7mZ"/>
31 </connections>
32 </barButtonItem>
33 <barButtonItem key="rightBarButtonItem" title="保存" id="tfS-NB-bAa">
34 <connections>
35 <action selector="saveButtonClicked:" destination="-1" id="Ct8-Yt-cqf"/>
36 </connections>
37 </barButtonItem>
38 </navigationItem>
39 </items>
40 </navigationBar>
41 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PpR-jP-zBp">
42 <rect key="frame" x="140" y="121" width="94" height="30"/>
43 <state key="normal" title="サウンド OFF"/>
44 <connections>
45 <action selector="btn0:" destination="-1" eventType="touchUpInside" id="D2i-qV-r6l"/>
46 </connections>
47 </button>
48 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AoY-L8-av3">
49 <rect key="frame" x="143" y="184" width="88" height="30"/>
50 <state key="normal" title="サウンド ON"/>
51 <connections>
52 <action selector="btn1:" destination="-1" eventType="touchUpInside" id="YsA-cp-CR4"/>
53 </connections>
54 </button>
55 </subviews>
56 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
57 <constraints>
58 <constraint firstItem="PpR-jP-zBp" firstAttribute="top" secondItem="MGO-KK-hkK" secondAttribute="bottom" constant="54" id="4bz-HU-IHi"/>
59 <constraint firstItem="AoY-L8-av3" firstAttribute="top" secondItem="PpR-jP-zBp" secondAttribute="bottom" constant="33" id="BWX-2h-now"/>
60 <constraint firstItem="MGO-KK-hkK" firstAttribute="centerX" secondItem="PpR-jP-zBp" secondAttribute="centerX" id="HE0-AV-Sn0"/>
61 <constraint firstItem="MGO-KK-hkK" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="JBI-H3-7oh"/>
62 <constraint firstItem="PpR-jP-zBp" firstAttribute="centerX" secondItem="AoY-L8-av3" secondAttribute="centerX" id="pYf-oQ-Q5a"/>
63 <constraint firstAttribute="trailing" secondItem="MGO-KK-hkK" secondAttribute="trailing" id="rjh-dO-gU9"/>
64 <constraint firstItem="MGO-KK-hkK" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="23" id="vcv-dy-VMf"/>
65 </constraints>
66 </view>
67 <barButtonItem title="Item" id="kIx-dO-d7Q"/>
68 </objects>
69 </document>
1 //
2 // Operation.h
3 // tuber
4 //
5 // Created by ドラッサル 亜嵐 on 2016/06/09.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10 #import "AFNetworking.h"
11
12 @interface Operation : NSObject
13
14 @property (nonatomic, strong) AFHTTPSessionManager *manager;
15 @property (nonatomic, strong) AFHTTPSessionManager *managerCustom;
16 @property (nonatomic, strong) AFHTTPSessionManager *managerImage;
17 @property (nonatomic, strong) AFHTTPSessionManager *managerRaw;
18 @property (nonatomic, strong) AFHTTPSessionManager *managerStreamToFile;
19
20 @property (nonatomic, strong) NSString *pcbDeviceId;
21 @property (nonatomic, strong) NSString *pcbDeviceType;
22 @property (nonatomic, strong) NSString *pcbDeviceModel;
23 @property (nonatomic, strong) NSString *pcbDeviceOs;
24
25 - (void)getFirmwareList:(NSString*)deviceId
26 deviceType:(NSString*)deviceType
27 deviceModel:(NSString*)deviceModel
28 deviceOs:(NSString*)deviceOs
29 appVersion:(NSString*)appVersion
30 success:(void(^)(id JSON))successHandler
31 failure:(void(^)(NSError *error, id JSON))failureHandler;
32 - (void)getImage:(NSString*)urlString success:(void(^)(id JSON))successHandler failure:(void(^)(NSError *error, id JSON))failureHandler;
33 - (void)getRaw:(NSString*)urlString
34 success:(void(^)(id JSON))successHandler
35 failure:(void(^)(NSError *error, id JSON))failureHandler;
36 - (UIImage*)getImageFromFile:(NSString*)filename;
37 - (void)streamToFile:(NSString*)urlString
38 saveToPath:(NSString*)saveToPath
39 progressBlock:(void(^)(double fractionCompleted))progressBlock
40 success:(void(^)(NSString *savedTo))successHandler
41 failure:(void(^)(NSError *error))failureHandler;
42 + (instancetype)sharedOperation;
43
44 @end
1 //
2 // SettingsController.h
3 // jacketparentweb
4 //
5 // Created by Chris Johnston on 11/28/16.
6 // Copyright © 2016 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12
13 typedef enum {
14 SETTINGS_CONTROLLER__EEPROM_READ_MODE,
15 SETTINGS_CONTROLLER__EEPROM_READ_MODE_DONE,
16 SETTINGS_CONTROLLER__EEPROM_READ_ID,
17 SETTINGS_CONTROLLER__EEPROM_READ_ID_DONE,
18 SETTINGS_CONTROLLER__EEPROM_READ_MODEL,
19 SETTINGS_CONTROLLER__EEPROM_READ_MODEL_DONE,
20 SETTINGS_CONTROLLER__EEPROM_READ_TYPE,
21 SETTINGS_CONTROLLER__EEPROM_READ_TYPE_DONE,
22 SETTINGS_CONTROLLER__EEPROM_READ_OS,
23 SETTINGS_CONTROLLER__EEPROM_READ_OS_DONE,
24 SETTINGS_CONTROLLER__EEPROM_READ_PIN,
25 SETTINGS_CONTROLLER__EEPROM_READ_PIN_DONE,
26 SETTINGS_CONTROLLER__DONE
27 } SettingsControllerCommandState;
28
29 @interface SettingsController : UIViewController <BLEProtocolDelegate> {
30 IBOutlet UILabel *lblDeviceMode;
31 IBOutlet UILabel *lblDeviceId;
32 IBOutlet UILabel *lblDeviceModel;
33 IBOutlet UILabel *lblDeviceType;
34 IBOutlet UILabel *lblDeviceOs;
35 IBOutlet UILabel *lblDevicePin;
36 SettingsControllerCommandState bleCommandState;
37 }
38
39 @property (nonatomic, strong) NSString *jacketId;
40 @property (strong, nonatomic) BLE *ble;
41 @property (strong, nonatomic) BleProtocol *protocol;
42 @property (nonatomic,assign) id <BLEProtocolDelegate> lastProtocolDelegate;
43
44 + (void)show:(NSString*)jacketId navigationController:(UINavigationController*)navigationController;
45
46 @end
1 //
2 // AppDelegate.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @interface AppDelegate : UIResponder <UIApplicationDelegate>
12
13 @property (strong, nonatomic) UIWindow *window;
14
15
16 @end
17
1 //
2 // AppDelegate.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "AppDelegate.h"
10 #import "jacket_test_ios-Swift.h"
11 @interface AppDelegate ()
12
13 @end
14
15 @implementation AppDelegate
16
17
18 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 // Override point for customization after application launch.
20 return [[Caller sheardInstance]application:application didFinishLaunchingWithOptions:launchOptions];
21 }
22
23 - (void)applicationWillResignActive:(UIApplication *)application {
24 // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 }
27
28 - (void)applicationDidEnterBackground:(UIApplication *)application {
29 // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 }
32
33 - (void)applicationWillEnterForeground:(UIApplication *)application {
34 // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 }
36
37 - (void)applicationDidBecomeActive:(UIApplication *)application {
38 // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 }
40
41 - (void)applicationWillTerminate:(UIApplication *)application {
42 // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 }
44
45 @end
1 {
2 "images" : [
3 {
4 "idiom" : "iphone",
5 "size" : "20x20",
6 "scale" : "2x"
7 },
8 {
9 "idiom" : "iphone",
10 "size" : "20x20",
11 "scale" : "3x"
12 },
13 {
14 "idiom" : "iphone",
15 "size" : "29x29",
16 "scale" : "2x"
17 },
18 {
19 "idiom" : "iphone",
20 "size" : "29x29",
21 "scale" : "3x"
22 },
23 {
24 "idiom" : "iphone",
25 "size" : "40x40",
26 "scale" : "2x"
27 },
28 {
29 "idiom" : "iphone",
30 "size" : "40x40",
31 "scale" : "3x"
32 },
33 {
34 "idiom" : "iphone",
35 "size" : "60x60",
36 "scale" : "2x"
37 },
38 {
39 "idiom" : "iphone",
40 "size" : "60x60",
41 "scale" : "3x"
42 },
43 {
44 "idiom" : "ipad",
45 "size" : "20x20",
46 "scale" : "1x"
47 },
48 {
49 "idiom" : "ipad",
50 "size" : "20x20",
51 "scale" : "2x"
52 },
53 {
54 "idiom" : "ipad",
55 "size" : "29x29",
56 "scale" : "1x"
57 },
58 {
59 "idiom" : "ipad",
60 "size" : "29x29",
61 "scale" : "2x"
62 },
63 {
64 "idiom" : "ipad",
65 "size" : "40x40",
66 "scale" : "1x"
67 },
68 {
69 "idiom" : "ipad",
70 "size" : "40x40",
71 "scale" : "2x"
72 },
73 {
74 "idiom" : "ipad",
75 "size" : "76x76",
76 "scale" : "1x"
77 },
78 {
79 "idiom" : "ipad",
80 "size" : "76x76",
81 "scale" : "2x"
82 },
83 {
84 "idiom" : "ipad",
85 "size" : "83.5x83.5",
86 "scale" : "2x"
87 }
88 ],
89 "info" : {
90 "version" : 1,
91 "author" : "xcode"
92 }
93 }
...\ No newline at end of file ...\ No newline at end of file
1 <?xml version="1.0" encoding="UTF-8"?>
2 <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3 <device id="retina4_7" orientation="portrait">
4 <adaptation id="fullscreen"/>
5 </device>
6 <dependencies>
7 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
8 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 </dependencies>
10 <scenes>
11 <!--View Controller-->
12 <scene sceneID="EHf-IW-A2E">
13 <objects>
14 <viewController id="01J-lp-oVM" sceneMemberID="viewController">
15 <layoutGuides>
16 <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
17 <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
18 </layoutGuides>
19 <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
20 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
21 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
22 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
23 </view>
24 </viewController>
25 <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
26 </objects>
27 <point key="canvasLocation" x="53" y="375"/>
28 </scene>
29 </scenes>
30 </document>
1 //
2 // BleControl.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BleProtocol.h"
11 #import "BLE.h"
12
13 @interface BleControl : UIViewController <BLEProtocolDelegate> {
14 IBOutlet UILabel *currentTime;
15 IBOutlet UILabel *currentState;
16 IBOutlet UILabel *currentUsetime;
17 IBOutlet UILabel *currentWalking;
18 IBOutlet UILabel *currentSleep;
19 IBOutlet UILabel *currentWake;
20 bool stateCurrentWalking;
21 }
22
23 @property (strong, nonatomic) BLE *ble;
24 @property (strong, nonatomic) BleProtocol *protocol;
25
26 - (IBAction)btnEditState:(id)sender;
27 - (IBAction)btnEditTime:(id)sender;
28 - (IBAction)btnEditSleep:(id)sender;
29 - (IBAction)btnEditWake:(id)sender;
30 - (IBAction)btnEditWalking:(id)sender;
31 - (IBAction)btnResetUsetime:(id)sender;
32 - (IBAction)btnUsetime:(id)sender;
33 - (void)getNextSlot;
34
35 @end
1 //
2 // BleControl.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "BleControl.h"
10
11 @interface BleControl ()
12
13 @property (nonatomic) NSInteger slotCounter;
14 @property (nonatomic) NSInteger slotCounterMin;
15 @property (nonatomic) NSInteger slotCounterMax;
16 @property (nonatomic) NSTimer * tmr;
17
18 @end
19
20 @implementation BleControl
21 @synthesize ble;
22 @synthesize protocol;
23
24 - (void)viewDidLoad {
25 [super viewDidLoad];
26
27 // Uncomment the following line to preserve selection between presentations.
28 // self.clearsSelectionOnViewWillAppear = NO;
29
30 // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
31 // self.navigationItem.rightBarButtonItem = self.editButtonItem;
32
33 self.slotCounterMin = 0;
34 self.slotCounterMax = 5;
35 self.slotCounter = self.slotCounterMin;
36 }
37
38 - (void)viewWillAppear:(BOOL)animated {
39 protocol.delegate = self;
40
41 self.tmr = [NSTimer timerWithTimeInterval:0.1
42 target:self
43 selector:@selector(tmrMethod:)
44 userInfo:nil
45 repeats:YES];
46 [[NSRunLoop currentRunLoop] addTimer:self.tmr forMode:NSRunLoopCommonModes];
47 }
48
49 - (void)viewWillDisappear:(BOOL)animated {
50 [self.tmr invalidate];
51 }
52
53 - (void)tmrMethod:(NSTimer *)timer {
54 [self getNextSlot];
55 }
56
57 - (void)didReceiveMemoryWarning {
58 [super didReceiveMemoryWarning];
59 // Dispose of any resources that can be recreated.
60 }
61
62 - (void)getNextSlot {
63 // TODO: Fix
64 /*
65 if(self.slotCounter == 0) {
66 [protocol getTime];
67 } else if(self.slotCounter == 1) {
68 [protocol getUsetime];
69 } else if(self.slotCounter == 2) {
70 [protocol getState];
71 } else if(self.slotCounter == 3) {
72 [protocol getSleep];
73 } else if(self.slotCounter == 4) {
74 [protocol getWake];
75 } else if(self.slotCounter == 5) {
76 [protocol getWalking];
77 }
78 */
79 self.slotCounter++;
80
81 if(self.slotCounter > self.slotCounterMax) {
82 self.slotCounter = self.slotCounterMin;
83 }
84 }
85
86 - (IBAction)btnEditState:(id)sender {
87 [self performSegueWithIdentifier:@"idSegueEditState" sender:self];
88 }
89
90 - (IBAction)btnEditTime:(id)sender {
91 [self performSegueWithIdentifier:@"idSegueEditTime" sender:self];
92 }
93
94 - (IBAction)btnEditSleep:(id)sender {
95 [self performSegueWithIdentifier:@"idSegueEditSleep" sender:self];
96 }
97
98 - (IBAction)btnEditWake:(id)sender {
99 [self performSegueWithIdentifier:@"idSegueEditWake" sender:self];
100 }
101
102 - (IBAction)btnEditWalking:(id)sender {
103 // TODO: Fix
104 if(stateCurrentWalking == false) {
105 //[protocol setWalking:true];
106 } else {
107 //[protocol setWalking:false];
108 }
109 }
110
111 - (IBAction)btnResetUsetime:(id)sender {
112 // TODO: Fix
113 //[protocol resetUsetime];
114 }
115
116 - (IBAction)btnUsetime:(id)sender {
117 [self performSegueWithIdentifier:@"idSegueUsetime" sender:self];
118 }
119
120 - (IBAction)btnCaseUnlock:(id)sender {
121 // TODO: Fix
122 //[protocol setUnlock];
123 }
124
125 - (void) protocolDidReceiveState:(NSString *)data text:(NSString *)text {
126 [currentState setText:text];
127 }
128
129 - (void) protocolDidReceiveTime:(NSString *) data {
130 [currentTime setText:data];
131 }
132
133 - (void) protocolDidReceiveSleepingBegin:(NSString *) data {
134 [currentSleep setText:data];
135 }
136
137 - (void) protocolDidReceiveSleepingEnd:(NSString *) data {
138 [currentWake setText:data];
139 }
140
141 - (void) protocolDidReceiveUsetime:(NSInteger) data {
142 int seconds = data % 60;
143 int minutes = (data / 60) % 60;
144 int hours = (int)data / 3600;
145
146 NSString *strUsetime = [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
147 [currentUsetime setText:strUsetime];
148 }
149
150 - (void) protocolDidReceiveUsetimeSlot:(NSInteger) dataSlot dataStamp:(NSTimeInterval) dataStamp dataUsetime: (NSInteger) dataUsetime {
151
152 }
153
154 - (void) protocolDidReceiveWalking:(BOOL)data {
155 stateCurrentWalking = data;
156 NSString *strData = [NSString alloc];
157
158 if(stateCurrentWalking == false) {
159 strData = @"無効";
160 } else {
161 strData = @"有効";
162 }
163 [currentWalking setText:strData];
164 }
165
166
167 @end
1
2 /*
3
4 Copyright (c) 2013-2014 RedBearLab
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
12 */
13
14 #import <Foundation/Foundation.h>
15 #import "BLE.h"
16 #import <UIKit/UIKit.h>
17
18 @protocol BLEProtocolDelegate
19 @optional
20 - (void)protocolDidGetData:(NSString *)type data:(NSString *)data;
21 @required
22 @end
23
24 @interface BleProtocol : NSObject
25 @property (strong, nonatomic) BLE *ble;
26 @property (nonatomic,assign) id <BLEProtocolDelegate> delegate;
27 - (void) parseData:(unsigned char *) data length:(int) length;
28
29 /* APIs for query and read/write pins */
30 - (void)sendCommand: (uint8_t *) data Length:(uint8_t) length;
31 - (void)sendDisconnect;
32 - (void)putData:(NSString *)type data:(NSString *)data;
33 - (void)bleWriteRaw:(NSData*)data;
34
35 @end
1 //
2 // DetailViewTableViewCell.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10
11 @interface BleSearchResultTableViewCell : UITableViewCell {
12 IBOutlet UILabel *lblUuidTapped;
13 IBOutlet UILabel *lblRssiTapped;
14 IBOutlet UILabel *lblNameTapped;
15 }
16
17 @property (strong, nonatomic) UILabel *lblUuid;
18 @property (strong, nonatomic) UILabel *lblRssi;
19 @property (strong, nonatomic) UILabel *lblName;
20
21 @end
1 //
2 // DetailViewTableViewCell.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "BleSearchResultTableViewCell.h"
10
11 @implementation BleSearchResultTableViewCell
12
13 - (void)awakeFromNib {
14 [super awakeFromNib];
15 // Initialization code
16 }
17
18 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
19 [super setSelected:selected animated:animated];
20
21 // Configure the view for the selected state
22 }
23
24 @end
1 //
2 // BleSearchResultTableViewController.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BLE.h"
11 #import "BleProtocol.h"
12
13 @interface BleSearchResultTableViewController : UITableViewController
14
15 @property (strong, nonatomic) BLE *ble;
16 @property (strong, nonatomic) BleProtocol *protocol;
17 @property (strong, nonatomic) NSMutableArray *BLEDevices;
18 @property (strong, nonatomic) NSMutableArray *BLEDevicesRssi;
19 @property (strong, nonatomic) NSMutableArray *BLEDevicesName;
20
21 @end
1 //
2 // BleSearchResultTableViewController.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "BleSearchResultTableViewController.h"
10 #import "BleSearchResultTableViewCell.h"
11
12 @interface BleSearchResultTableViewController ()
13
14 @end
15
16 @implementation BleSearchResultTableViewController
17
18 @synthesize ble;
19 @synthesize BLEDevicesRssi;
20
21 - (void)viewDidLoad {
22 [super viewDidLoad];
23
24 // Uncomment the following line to preserve selection between presentations.
25 // self.clearsSelectionOnViewWillAppear = NO;
26
27 // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
28 // self.navigationItem.rightBarButtonItem = self.editButtonItem;
29
30 self.BLEDevicesRssi = [NSMutableArray arrayWithArray:ble.peripheralsRssi];
31 }
32
33 - (void)didReceiveMemoryWarning {
34 [super didReceiveMemoryWarning];
35 // Dispose of any resources that can be recreated.
36 }
37
38 -(void) connectionTimer:(NSTimer *)timer
39 {
40 [self.BLEDevices removeAllObjects];
41 [self.BLEDevicesRssi removeAllObjects];
42 [self.BLEDevicesName removeAllObjects];
43
44 if (ble.peripherals.count > 0)
45 {
46 for (int i = 0; i < ble.peripherals.count; i++)
47 {
48 CBPeripheral *p = [ble.peripherals objectAtIndex:i];
49 NSNumber *n = [ble.peripheralsRssi objectAtIndex:i];
50 NSString *name = [[ble.peripherals objectAtIndex:i] name];
51
52 if (p.identifier.UUIDString != NULL)
53 {
54 [self.BLEDevices insertObject:p.identifier.UUIDString atIndex:i];
55 [self.BLEDevicesRssi insertObject:n atIndex:i];
56
57 if (name != nil)
58 {
59 [self.BLEDevicesName insertObject:name atIndex:i];
60 }
61 else
62 {
63 [self.BLEDevicesName insertObject:@"RedBear Device" atIndex:i];
64 }
65 }
66 else
67 {
68 [self.BLEDevices insertObject:@"NULL" atIndex:i];
69 [self.BLEDevicesRssi insertObject:@"0" atIndex:i];
70 [self.BLEDevicesName insertObject:@"RedBear Device" atIndex:i];
71 }
72 }
73 }
74 else
75 {
76 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
77 message:@"No BLE Device(s) found."
78 delegate:nil
79 cancelButtonTitle:@"OK"
80 otherButtonTitles:nil];
81 [alert show];
82 }
83
84 [self.tableView reloadData];
85 }
86
87 #pragma mark - Table view data source
88
89 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
90 // Return the number of sections.
91 return 1;
92 }
93
94 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
95 // Return the number of rows in the section.
96 return self.BLEDevices.count;
97 }
98
99 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
100 {
101 static NSString *tableIdentifier = @"cell_uuid";
102 BleSearchResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier forIndexPath:indexPath];
103
104 // Configure the cell...
105 UIFont *newFont = [UIFont fontWithName:@"Arial" size:13.5];
106
107 cell.lblUuid.font = newFont;
108 cell.lblUuid.text = [self.BLEDevices objectAtIndex:indexPath.row];
109
110 newFont = [UIFont fontWithName:@"Arial" size:11.0];
111 cell.lblRssi.font = newFont;
112 NSMutableString *rssiString = [NSMutableString stringWithFormat:@"RSSI : %@", [self.BLEDevicesRssi objectAtIndex:indexPath.row]];
113 cell.lblRssi.text = rssiString;
114
115 newFont = [UIFont fontWithName:@"Arial" size:13.0];
116 cell.lblName.font = newFont;
117 cell.lblName.text = [self.BLEDevicesName objectAtIndex:indexPath.row];
118
119 return cell;
120 }
121
122 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
123 {
124 if(ble.isConnected) {
125 [self.protocol sendDisconnect];
126 }
127 [ble connectPeripheral:[ble.peripherals objectAtIndex:indexPath.row]];
128 }
129
130 @end
1 //
2 // ViewController.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "BLE.h"
11 #import "BleProtocol.h"
12
13 @interface BleSearchViewController : UIViewController <BLEDelegate>
14 {
15 IBOutlet UIActivityIndicatorView *activityScanning;
16 IBOutlet UIButton *btnConnect;
17 IBOutlet UIButton *btnConnectLast;
18 IBOutlet UILabel *lblVersion;
19 BOOL showAlert;
20 bool isFindingLast;
21 }
22
23 @property (strong, nonatomic) BLE *ble;
24 @property (strong, nonatomic) BleProtocol *protocol;
25 @property (strong, nonatomic) NSMutableArray *mDevices;
26 @property (strong, nonatomic) NSMutableArray *mDevicesName;
27 @property (strong,nonatomic) NSString *lastUUID;
28
29 - (IBAction)btnConnectClicked:(id)sender;
30 - (IBAction)lastClick:(id)sender;
31 - (void)bleDidConnect;
32 - (void)bleDidDisconnect;
33 - (void)bleDidReceiveData:(unsigned char *)data length:(int)length;
34 - (void)bleDidUpdateRSSI:(NSNumber *) rssi;
35 - (NSString *)getUUIDString:(CFUUIDRef)ref;
36
37 @end
38
1 //
2 // BleSearchViewController.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "BleSearchViewController.h"
10 #import "BleControl.h"
11 #import "BleSearchResultTableViewController.h"
12 #import "SettingsController.h"
13 #import "Operation.h"
14 #import "jacket_test_ios-Swift.h"
15
16 @interface BleSearchViewController ()
17
18 @end
19
20 NSString * const UUIDPrefKey = @"UUIDPrefKey";
21
22 @implementation BleSearchViewController
23 @synthesize ble;
24 @synthesize protocol;
25 BleControl *cv;
26
27 - (void)viewDidLoad {
28 [super viewDidLoad];
29 // Do any additional setup after loading the view, typically from a nib.
30
31 ble = [[BLE alloc] init];
32 [ble controlSetup];
33 ble.delegate = self;
34
35 self.mDevices = [[NSMutableArray alloc] init];
36 self.mDevicesName = [[NSMutableArray alloc] init];
37
38 if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
39 {
40 [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:UUIDPrefKey];
41 }
42
43 //Retrieve saved UUID from system
44 self.lastUUID = [[NSUserDefaults standardUserDefaults] objectForKey:UUIDPrefKey];
45 if ([self.lastUUID isEqualToString:@""])
46 {
47 [btnConnectLast setEnabled:NO];
48 }
49 else
50 {
51 [btnConnectLast setEnabled:YES];
52 }
53
54 protocol = [[BleProtocol alloc] init];
55 protocol.ble = ble;
56 }
57
58 - (void)didReceiveMemoryWarning {
59 [super didReceiveMemoryWarning];
60 // Dispose of any resources that can be recreated.
61 }
62
63 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
64 {
65 if ([[segue identifier] isEqualToString:@"idSegueBleDeviceList"])
66 {
67 BleSearchResultTableViewController *vc = [segue destinationViewController];
68 vc.BLEDevices = self.mDevices;
69 vc.BLEDevicesName = self.mDevicesName;
70 vc.ble = ble;
71 vc.protocol = protocol;
72 }
73 else if ([[segue identifier] isEqualToString:@"idSegueBleDevice"])
74 {
75 cv = [segue destinationViewController];
76 cv.ble = ble;
77 cv.protocol = protocol;
78 }
79 }
80
81 - (void)connectionTimer:(NSTimer *)timer
82 {
83 showAlert = YES;
84 [btnConnect setEnabled:YES];
85
86 self.lastUUID = [[NSUserDefaults standardUserDefaults] objectForKey:UUIDPrefKey];
87
88 if ([self.lastUUID isEqualToString:@""])
89 {
90 [btnConnectLast setEnabled:NO];
91 }
92 else
93 {
94 [btnConnectLast setEnabled:YES];
95 }
96
97 if (ble.peripherals.count > 0)
98 {
99 if(isFindingLast)
100 {
101 int i;
102 for (i = 0; i < ble.peripherals.count; i++)
103 {
104 CBPeripheral *p = [ble.peripherals objectAtIndex:i];
105
106 if (p.identifier.UUIDString != NULL)
107 {
108 //Comparing UUIDs and call connectPeripheral is matched
109 if([self.lastUUID isEqualToString:p.identifier.UUIDString])
110 {
111 showAlert = NO;
112 [ble connectPeripheral:p];
113 }
114 }
115 }
116 }
117 else
118 {
119 [self.mDevices removeAllObjects];
120 [self.mDevicesName removeAllObjects];
121
122 int i;
123 for (i = 0; i < ble.peripherals.count; i++)
124 {
125 CBPeripheral *p = [ble.peripherals objectAtIndex:i];
126
127 if (p.identifier.UUIDString != NULL)
128 {
129 [self.mDevices insertObject:p.identifier.UUIDString atIndex:i];
130 if (p.name != nil) {
131 [self.mDevicesName insertObject:p.name atIndex:i];
132 } else {
133 [self.mDevicesName insertObject:@"RedBear Device" atIndex:i];
134 }
135 }
136 else
137 {
138 [self.mDevices insertObject:@"NULL" atIndex:i];
139 [self.mDevicesName insertObject:@"RedBear Device" atIndex:i];
140 }
141 }
142 showAlert = NO;
143 [self performSegueWithIdentifier:@"idSegueBleDeviceList" sender:self];
144 }
145 }
146
147 if (showAlert == YES) {
148 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
149 message:@"No BLE Device(s) found."
150 delegate:nil
151 cancelButtonTitle:@"OK"
152 otherButtonTitles:nil];
153 [alert show];
154 }
155
156 [activityScanning stopAnimating];
157 }
158
159 - (IBAction)btnConnectClicked:(id)sender
160 {
161 if (ble.activePeripheral)
162 if(ble.activePeripheral.state == CBPeripheralStateConnected)
163 {
164 [[ble CM] cancelPeripheralConnection:[ble activePeripheral]];
165 return;
166 }
167
168 if (ble.peripherals)
169 ble.peripherals = nil;
170
171 [btnConnect setEnabled:false];
172 [btnConnectLast setEnabled:NO];
173 [ble findBLEPeripherals:3];
174
175 [NSTimer scheduledTimerWithTimeInterval:(float)3.0 target:self selector:@selector(connectionTimer:) userInfo:nil repeats:NO];
176
177 isFindingLast = false;
178 [activityScanning startAnimating];
179 }
180
181 - (IBAction)lastClick:(id)sender {
182 if (ble.peripherals) {
183 ble.peripherals = nil;
184 }
185
186 [btnConnect setEnabled:false];
187 [btnConnectLast setEnabled:NO];
188 [ble findBLEPeripherals:3];
189
190 [NSTimer scheduledTimerWithTimeInterval:(float)3.0 target:self selector:@selector(connectionTimer:) userInfo:nil repeats:NO];
191
192 isFindingLast = true;
193 [activityScanning startAnimating];
194 }
195
196 - (void) bleDidConnect
197 {
198 NSLog(@"->DidConnect");
199
200 self.lastUUID = ble.activePeripheral.identifier.UUIDString;
201 [[NSUserDefaults standardUserDefaults] setObject:self.lastUUID forKey:UUIDPrefKey];
202 [[NSUserDefaults standardUserDefaults] synchronize];
203
204 self.lastUUID = [[NSUserDefaults standardUserDefaults] objectForKey:UUIDPrefKey];
205 if ([self.lastUUID isEqualToString:@""]) {
206 [btnConnectLast setEnabled:NO];
207 } else {
208 [btnConnectLast setEnabled:YES];
209 }
210
211 [activityScanning stopAnimating];
212
213 [self populatePcbInfo];
214
215 [SettingsController show:(NSString *)protocol navigationController:self.navigationController];
216 }
217
218 - (void)bleDidDisconnect
219 {
220 NSLog(@"->DidDisconnect");
221
222 [activityScanning stopAnimating];
223 [self.navigationController popToRootViewControllerAnimated:true];
224 }
225
226 - (void)populatePcbInfo {
227 if([Operation sharedOperation].pcbDeviceId == nil) {
228 [protocol putData:@"infoDeviceId" data:nil];
229 } else if([Operation sharedOperation].pcbDeviceType == nil) {
230 [protocol putData:@"infoDeviceType" data:nil];
231 } else if([Operation sharedOperation].pcbDeviceModel == nil) {
232 [protocol putData:@"infoDeviceModel" data:nil];
233 } else if([Operation sharedOperation].pcbDeviceOs == nil) {
234 [protocol putData:@"infoDeviceOs" data:nil];
235 }
236 }
237
238 - (void) bleDidReceiveData:(unsigned char *)data length:(int)length
239 {
240
241 NSLog(@"data!!!%s", data);
242
243 for(int i = 0; i < length; i++) {
244 if((data[i] < 32) || (data[i] > 127)) {
245 data[i] = ' ';
246 }
247 }
248 NSString* dataString = [NSString stringWithCString: (const char *)data encoding:NSUTF8StringEncoding];
249 dataString = [dataString substringToIndex:length];
250
251
252 NSLog(@"->DidReceiveData- %@",dataString);
253
254 if([dataString hasPrefix:@"ii"]) {
255 [Operation sharedOperation].pcbDeviceId = [dataString substringWithRange:NSMakeRange(2, [dataString length] - 3)];
256 [self populatePcbInfo];
257 } else if ([dataString hasPrefix:@"it"]) {
258 [Operation sharedOperation].pcbDeviceType = [dataString substringWithRange:NSMakeRange(2, [dataString length] - 3)];
259 [self populatePcbInfo];
260 } else if ([dataString hasPrefix:@"im"]) {
261 [Operation sharedOperation].pcbDeviceModel = [dataString substringWithRange:NSMakeRange(2, [dataString length] - 3)];
262 [self populatePcbInfo];
263 } else if ([dataString hasPrefix:@"io"]) {
264 [Operation sharedOperation].pcbDeviceOs = [dataString substringWithRange:NSMakeRange(2, [dataString length] - 3)];
265 [self populatePcbInfo];
266 }
267
268 [protocol parseData:data length:length];
269 /* for iot Demo */
270 [[Caller sheardInstance] proximityNofitication :[SenserData sheardInstance].proximity ];
271 /* for iot Demo end */
272 }
273
274 - (void) bleDidUpdateRSSI:(NSNumber *) rssi
275 {
276 }
277
278 - (NSString *)getUUIDString:(CFUUIDRef)ref {
279 NSString *str = [NSString stringWithFormat:@"%@", ref];
280 return [[NSString stringWithFormat:@"%@", str] substringWithRange:NSMakeRange(str.length - 36, 36)];
281 }
282
283 @end
1 //
2 // caller.swift
3 // jacket_test_ios
4 //
5 // Created by USER on 2017/10/11.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 import Foundation
10 import UIKit
11 import UserNotifications
12 class Caller:NSObject{
13 public static let sheardInstance:Caller = Caller()
14
15 public func proximityNofitication(_ data:Int){
16 if(data > 100 ){return}
17 if #available(iOS 10.0, *) {
18 NSLog("yobareta");
19 UserNofitication.sharedInstance.easyNofitication(
20 /* nofitication detail */
21 identifier : "nofity",
22 title : "データが届きました",
23 body : String(data) + "cm",
24 actions : [
25 UNNotificationAction(
26 identifier: "possitive",
27 title: "",
28 options:[])], completionHandler: ({(Error)->Void in
29
30 }),
31
32 /* response callback */
33 response : UNResponseManager.sharedInstance.setResponse(identifier: "nofity") {(_ actionIdentifier:String) in
34 switch actionIdentifier {
35 case "positive":
36
37
38 break
39 case UNNotificationDismissActionIdentifier:
40 /* 選択せずにnofiticationを消去の場合*/
41 break
42 case UNNotificationDefaultActionIdentifier:
43 /* 選択せずにアプリ起動場合*/
44 break
45 default:
46 break
47 }
48 })
49 } else {
50 // Fallback on earlier versions
51 }
52 }
53
54 public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
55
56 if #available(iOS 10.0, *) {
57 let center = UNUserNotificationCenter.current()
58 center.requestAuthorization(options: [.alert], completionHandler: { (granted, error) in
59 if error != nil {
60 print(error?.localizedDescription)
61 return
62 }
63 })
64 }
65
66 return true
67 }
68 }
69
1 //
2 // caller.swift
3 // jacket_test_ios
4 //
5 // Created by USER on 2017/10/11.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 import Foundation
10 class Caller{
11 UserNofitication.sharedInstance.easyNofitication(
12 /* nofitication detail */
13 identifier : "accident",
14 title : DefaultText.AccidentTitle.rawValue,
15 body : DefaultText.AccidentBody.rawValue,
16 actions : [
17 UNNotificationAction(
18 identifier:"negative",
19 title: DefaultText.AccidentNegativeButton.rawValue,
20 options: []),
21 UNNotificationAction(
22 identifier: "possitive",
23 title: DefaultText.AccidentPositiveButton.rawValue,
24 options:[])], completionHandler: ({(Error)->Void in
25
26 /* 応答がなければ アクシデントとみなす */
27
28 if(UserState.instance._hasAccident)!{
29 _ = Timer.scheduledTimer(
30 timeInterval: 120.0,
31 target : self,
32 selector : #selector(core_functions.sharedInstance.accidentHappend),
33 userInfo : nil,
34 repeats : false ).fire()
35 }
36
37
38 }),
39
40 /* response callback */
41 response : UNResponseManager.sharedInstance.setResponse(identifier: "accident") {(_ actionIdentifier:String) in
42
43 NSLog("accident happend")
44 switch actionIdentifier {
45 case "negative":
46 core_functions.sharedInstance.accidentHappend()
47 break
48 case "positive":
49 core_functions.sharedInstance.accidentCancel()
50 break
51 case UNNotificationDismissActionIdentifier:
52 /* 選択せずにnofiticationを消去の場合*/
53 break
54 case UNNotificationDefaultActionIdentifier:
55 /* 選択せずにアプリ起動場合*/
56 break
57 default:
58 break
59 }
60 })
61 }
62 }
1 //
2 // DemoViewController.swift
3 // jacket_test_ios
4 //
5 // Created by USER on 2017/10/11.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 import UIKit
10
11 class DemoViewController: UIViewController {
12
13 override func viewDidLoad() {
14 super.viewDidLoad()
15
16 // Do any additional setup after loading the view.
17 }
18
19 override func didReceiveMemoryWarning() {
20 super.didReceiveMemoryWarning()
21 // Dispose of any resources that can be recreated.
22 }
23
24
25 /*
26 // MARK: - Navigation
27
28 // In a storyboard-based application, you will often want to do a little preparation before navigation
29 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
30 // Get the new view controller using segue.destinationViewController.
31 // Pass the selected object to the new view controller.
32 }
33 */
34
35 }
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3 <plist version="1.0">
4 <dict>
5 <key>CFBundleDevelopmentRegion</key>
6 <string>en</string>
7 <key>CFBundleDisplayName</key>
8 <string>jacket_test_ios</string>
9 <key>CFBundleExecutable</key>
10 <string>$(EXECUTABLE_NAME)</string>
11 <key>CFBundleIdentifier</key>
12 <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13 <key>CFBundleInfoDictionaryVersion</key>
14 <string>6.0</string>
15 <key>CFBundleName</key>
16 <string>$(PRODUCT_NAME)</string>
17 <key>CFBundlePackageType</key>
18 <string>APPL</string>
19 <key>CFBundleShortVersionString</key>
20 <string>0.1</string>
21 <key>CFBundleSignature</key>
22 <string>????</string>
23 <key>CFBundleVersion</key>
24 <string>1</string>
25 <key>LSRequiresIPhoneOS</key>
26 <true/>
27 <key>NSAppTransportSecurity</key>
28 <dict>
29 <key>NSAllowsArbitraryLoads</key>
30 <true/>
31 </dict>
32 <key>UILaunchStoryboardName</key>
33 <string>LaunchScreen</string>
34 <key>UIMainStoryboardFile</key>
35 <string>Main</string>
36 <key>UIRequiredDeviceCapabilities</key>
37 <array>
38 <string>armv7</string>
39 </array>
40 <key>UISupportedInterfaceOrientations</key>
41 <array>
42 <string>UIInterfaceOrientationPortrait</string>
43 </array>
44 <key>UISupportedInterfaceOrientations~ipad</key>
45 <array>
46 <string>UIInterfaceOrientationPortrait</string>
47 <string>UIInterfaceOrientationPortraitUpsideDown</string>
48 <string>UIInterfaceOrientationLandscapeLeft</string>
49 <string>UIInterfaceOrientationLandscapeRight</string>
50 </array>
51 </dict>
52 </plist>
1 //
2 // NSData+NSString.h
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/07.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <Foundation/Foundation.h>
10
11 @interface NSData (NSString)
12
13 - (NSString *)toString;
14
15 @end
1 //
2 // NSData+NSString.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2017/06/07.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import "NSData+NSString.h"
10
11 @implementation NSData (NSString)
12
13 - (NSString *)toString
14 {
15 Byte *dataPointer = (Byte *)[self bytes];
16 NSMutableString *result = [NSMutableString stringWithCapacity:0];
17 NSUInteger index;
18 for (index = 0; index < [self length]; index++)
19 {
20 [result appendFormat:@"0x%02x,", dataPointer[index]];
21 }
22 return result;
23 }
24
25 @end
1 //
2 // Data.swift
3 // jacket_test_ios
4 //
5 // Created by USER on 2017/10/11.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 import Foundation
10
11 class SenserData:NSObject{
12 public static let sheardInstance:SenserData = SenserData()
13
14 public var data:String = "1"
15 public var proximity:Int = 0
16
17
18 public func setData(_ type:String,data:String){
19 switch type {
20 case "03":
21 proximity = Int(data, radix: 16)!
22 break
23 default:
24 break
25 }
26 }
27
28 public func parseData(_ data:String)->[String]?{
29 if(5 > data.count ){return nil}
30
31 var parsed = [String]()
32 parsed.append(substr(data,start: 0, end: 4))
33 NSLog(substr(data,start: 0, end: 4))
34 parsed.append(substr(data,start: 4, end: 8))
35 NSLog(substr(data,start: 4, end: 8))
36 parsed.append(substr(data,start: 8, end: 10))
37 NSLog(substr(data,start: 8, end: 10))
38 parsed.append(substr(data,start: 10, end: 14))
39 parsed.append(substr(data,start: 14, end: 16))
40
41 return parsed
42 }
43
44 public func lessThan(_ val:Int , of:Int)->Int?{
45 if(val < of){ return of }
46 return nil
47 }
48 private func substr(_ str:String,start:Int,end:Int)->String{
49 let startIndex = str.index(str.startIndex, offsetBy: start)
50 let endIndex = str.index(str.startIndex, offsetBy: end)
51 return str.substring(with: startIndex..<endIndex)
52 }
53 }
1 //
2 // UserNofiticationManager.swift
3 // ko-seigen
4 //
5 // Created by USER on 2017/10/04.
6 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 import Foundation
10 //
11 // UNNofiticationResponse.swift
12 // ko-seigen
13 //
14 // Created by USER on 2017/10/04.
15 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
16 //
17
18 import Foundation
19 import UserNotifications
20
21 class UNResponseManager:NSObject, UNUserNotificationCenterDelegate{
22
23 static let sharedInstance = UNResponseManager();
24 private var Response:[String:((_ actionIdentifier:String) -> Void )] = [:]
25
26 public func setResponse( identifier:String,response:@escaping ((_ actionIdentifier:String) -> Void ))
27 ->UNResponseManager{
28 if(Response[identifier] == nil){
29 Response[identifier] = response
30 }
31 return self
32 }
33
34 @available(iOS 10.0, *)
35 func userNotificationCenter(_ center: UNUserNotificationCenter,
36 willPresent notification: UNNotification,
37 withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
38 completionHandler([.alert,.sound])
39 NSLog("called")
40 }
41
42 @available(iOS 10.0, *)
43 func userNotificationCenter(_ center: UNUserNotificationCenter,
44 didReceive response: UNNotificationResponse,
45 withCompletionHandler completionHandler: @escaping () -> Void) {
46
47 let id = response.notification.request.content.categoryIdentifier
48 if(Response[id] != nil){
49 Response[id]!(response.actionIdentifier)
50 }
51 completionHandler()
52 }
53
54 }
55
1 import Foundation
2 //
3 // UNNofitication.swift
4 // ko-seigen
5 //
6 // Created by USER on 2017/10/04.
7 // Copyright © 2017年 ドラッサル 亜嵐. All rights reserved.
8 //
9
10 import Foundation
11 import UserNotifications
12
13 class UserNofitication:NSObject{
14 static let sharedInstance = UserNofitication()
15 @available(iOS 10.0, *)
16 public func easyNofitication(
17 identifier : String,
18 title : String,
19 body : String,
20 actions : [UNNotificationAction],
21 completionHandler :((Error?) -> Void)?,
22 response :UNResponseManager
23 ){
24
25
26 let category = UNNotificationCategory(identifier: identifier,
27 actions: actions ,
28 intentIdentifiers: [],
29 options: [])
30
31 UNUserNotificationCenter.current().setNotificationCategories([category])
32
33
34 let content = UNMutableNotificationContent()
35 content.title = title
36 content.body = body
37 content.sound = UNNotificationSound.default()
38 content.categoryIdentifier = identifier
39
40
41 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
42 let request = UNNotificationRequest(identifier: identifier,
43 content: content,
44 trigger: trigger)
45 let center = UNUserNotificationCenter.current()
46 center.delegate = UNResponseManager.sharedInstance
47 center.add(request, withCompletionHandler:completionHandler)
48
49 }
50 }
51
1 //
2 // Use this file to import your target's public headers that you would like to expose to Swift.
3 //
4
1 //
2 // main.m
3 // jacket_ios
4 //
5 // Created by ドラッサル 亜嵐 on 2016/04/27.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #import <UIKit/UIKit.h>
10 #import "AppDelegate.h"
11
12 int main(int argc, char * argv[]) {
13 @autoreleasepool {
14 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 }
16 }
1 //
2 // jacket_ios_prefix.pch
3 // tuber
4 //
5 // Created by ドラッサル 亜嵐 on 2016/06/09.
6 // Copyright © 2016年 ドラッサル 亜嵐. All rights reserved.
7 //
8
9 #ifndef jacket_ios_prefix_pch
10 #define jacket_ios_prefix_pch
11
12 // Include any system framework and library headers here that should be included in all compilation units.
13 // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
14
15 #define URL_BASE @"http://jacketapi.momo-ltd.com"
16 #define URL_PATH_API @"/jacketapi/%@"
17
18 #define URL_PATH_STORE_FIRMWARE @"/jacketapi/firmware_download.php?uuid=%@"
19
20 #define USER_USERID @"username"
21 #define USER_PASSWORD @"password"
22
23 #define KEY_USER_USERID @"username"
24 #define KEY_USER_PASSWORD @"password"
25
26 #define AGENT_KEY @"agent"
27 #define VNAME_KEY @"vname"
28
29 #define DATABASE @"sqlitedb.sql"
30
31 #endif /* Tuber_Prefix_pch */