first

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