diff --git a/OneTimePasswordExample.xcodeproj/project.pbxproj b/OneTimePasswordExample.xcodeproj/project.pbxproj index 83174b4..635e20d 100644 --- a/OneTimePasswordExample.xcodeproj/project.pbxproj +++ b/OneTimePasswordExample.xcodeproj/project.pbxproj @@ -14,6 +14,9 @@ 08C8E27826BBA377006D4608 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 08C8E27726BBA377006D4608 /* Assets.xcassets */; }; 08C8E27B26BBA377006D4608 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 08C8E27926BBA377006D4608 /* LaunchScreen.storyboard */; }; 08C8E27E26BBA377006D4608 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C8E27D26BBA377006D4608 /* main.m */; }; + 4F8B41252703520D00CF6A1A /* SettingController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F8B41242703520D00CF6A1A /* SettingController.m */; }; + 4F8B41292705F8CF00CF6A1A /* SettingsTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F8B41282705F8CF00CF6A1A /* SettingsTableViewCell.m */; }; + 4F8B412D2709A50E00CF6A1A /* SettingTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4F8B412C2709A50E00CF6A1A /* SettingTableViewCell.xib */; }; 9A376FD397E03D93D3D80530 /* libPods-OneTimePasswordExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C08B5529218DAFE111F19B53 /* libPods-OneTimePasswordExample.a */; }; /* End PBXBuildFile section */ @@ -30,6 +33,11 @@ 08C8E27A26BBA377006D4608 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 08C8E27C26BBA377006D4608 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 08C8E27D26BBA377006D4608 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 4F8B41242703520D00CF6A1A /* SettingController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingController.m; sourceTree = ""; }; + 4F8B4126270484D900CF6A1A /* SettingController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingController.h; sourceTree = ""; }; + 4F8B41272705F8A900CF6A1A /* SettingsTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsTableViewCell.h; sourceTree = ""; }; + 4F8B41282705F8CF00CF6A1A /* SettingsTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsTableViewCell.m; sourceTree = ""; }; + 4F8B412C2709A50E00CF6A1A /* SettingTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingTableViewCell.xib; sourceTree = ""; }; 62EA47A9FA5474BBDDECC144 /* Pods-OneTimePasswordExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneTimePasswordExample.debug.xcconfig"; path = "Target Support Files/Pods-OneTimePasswordExample/Pods-OneTimePasswordExample.debug.xcconfig"; sourceTree = ""; }; C08B5529218DAFE111F19B53 /* libPods-OneTimePasswordExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OneTimePasswordExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C0CF9A46AE07C0F1865C69D3 /* Pods-OneTimePasswordExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneTimePasswordExample.release.xcconfig"; path = "Target Support Files/Pods-OneTimePasswordExample/Pods-OneTimePasswordExample.release.xcconfig"; sourceTree = ""; }; @@ -68,13 +76,18 @@ 08C8E26A26BBA376006D4608 /* OneTimePasswordExample */ = { isa = PBXGroup; children = ( + 4F8B41272705F8A900CF6A1A /* SettingsTableViewCell.h */, + 4F8B41282705F8CF00CF6A1A /* SettingsTableViewCell.m */, 08C8E26B26BBA376006D4608 /* AppDelegate.h */, 08C8E26C26BBA376006D4608 /* AppDelegate.m */, 08C8E26E26BBA376006D4608 /* SceneDelegate.h */, 08C8E26F26BBA376006D4608 /* SceneDelegate.m */, 08C8E27126BBA376006D4608 /* ViewController.h */, 08C8E27226BBA376006D4608 /* ViewController.m */, + 4F8B41242703520D00CF6A1A /* SettingController.m */, + 4F8B4126270484D900CF6A1A /* SettingController.h */, 08C8E27426BBA376006D4608 /* Main.storyboard */, + 4F8B412C2709A50E00CF6A1A /* SettingTableViewCell.xib */, 08C8E27726BBA377006D4608 /* Assets.xcassets */, 08C8E27926BBA377006D4608 /* LaunchScreen.storyboard */, 08C8E27C26BBA377006D4608 /* Info.plist */, @@ -159,6 +172,7 @@ files = ( 08C8E27B26BBA377006D4608 /* LaunchScreen.storyboard in Resources */, 08C8E27826BBA377006D4608 /* Assets.xcassets in Resources */, + 4F8B412D2709A50E00CF6A1A /* SettingTableViewCell.xib in Resources */, 08C8E27626BBA376006D4608 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -197,6 +211,8 @@ files = ( 08C8E27326BBA376006D4608 /* ViewController.m in Sources */, 08C8E26D26BBA376006D4608 /* AppDelegate.m in Sources */, + 4F8B41292705F8CF00CF6A1A /* SettingsTableViewCell.m in Sources */, + 4F8B41252703520D00CF6A1A /* SettingController.m in Sources */, 08C8E27E26BBA377006D4608 /* main.m in Sources */, 08C8E27026BBA376006D4608 /* SceneDelegate.m in Sources */, ); diff --git a/OneTimePasswordExample/Base.lproj/Main.storyboard b/OneTimePasswordExample/Base.lproj/Main.storyboard index 5baab28..4ed1ae6 100644 --- a/OneTimePasswordExample/Base.lproj/Main.storyboard +++ b/OneTimePasswordExample/Base.lproj/Main.storyboard @@ -1,8 +1,9 @@ - + - + + @@ -11,7 +12,7 @@ - + @@ -29,18 +30,30 @@ + + + + + @@ -48,7 +61,65 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OneTimePasswordExample/SettingController.h b/OneTimePasswordExample/SettingController.h new file mode 100644 index 0000000..bf6b828 --- /dev/null +++ b/OneTimePasswordExample/SettingController.h @@ -0,0 +1,20 @@ +// +// SettingController.h +// OneTimePasswordExample +// +// Created by Mai Nakagami on 2021/09/29. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SettingController : UITableViewController + +@property (nonatomic) NSString *test1; +@property (nonatomic) NSString *test2; +@property (nonatomic) NSString *test3; + +@end + +NS_ASSUME_NONNULL_END diff --git a/OneTimePasswordExample/SettingController.m b/OneTimePasswordExample/SettingController.m new file mode 100644 index 0000000..a996bd6 --- /dev/null +++ b/OneTimePasswordExample/SettingController.m @@ -0,0 +1,156 @@ +// +// SettingController.m +// OneTimePasswordExample +// +// Created by Mai Nakagami on 2021/09/28. +// + +#import "SettingController.h" +#import "SettingsTableViewCell.h" +#import "ViewController.h" + +#pragma mark - Settings item + +typedef NS_ENUM(UInt8, SettingsItem) { + SettingsItem1, + SettingsItem2, + SettingsItme3, +}; + +extern SettingsItem SettingsItemUnknown; + + +#pragma mark - Settings table view controller + +@interface SettingController () + +@property (nonatomic) SettingsItem settingsItem; + +@property (nonatomic) UIPickerView *pickerView; + +@property (nonatomic) NSArray *test1Patterns; +@property (nonatomic) NSArray *test2Patterns; +@property (nonatomic) NSArray *test3Patterns; + +@end + +@implementation SettingController { + NSIndexPath * pickerIndexPath; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.pickerView = [[UIPickerView alloc] init]; + self.pickerView.center = self.view.center; + self.pickerView.dataSource = self; + self.pickerView.delegate = self; + [self.view addSubview: self.pickerView]; + + self.test1Patterns = @[@"SHA1", @"SHA256", @"SHA512"]; + self.test2Patterns = @[@"4", @"5", @"6", @"7", @"8", @"9", @"10"]; + self.test3Patterns = @[@"30", @"60"]; + + self.test1 = self.test1Patterns[0]; + self.test2 = self.test2Patterns[0]; + self.test3 = self.test3Patterns[0]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 3; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + SettingsTableViewCell *cell = (SettingsTableViewCell *)[tableView dequeueReusableCellWithIdentifier: @"SettingsTableViewCell" forIndexPath:indexPath]; + + switch (indexPath.row) { + case 0: + cell.titleLabel.text = @"アルゴリズム"; + cell.valueLabel.text = self.test1; + break; + case 1: + cell.titleLabel.text = @"OTP桁数"; + cell.valueLabel.text = self.test2; + break; + case 2: + cell.titleLabel.text = @"タイムステップ数"; + cell.valueLabel.text = self.test3; + break; + } + + return cell; +} + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + self.settingsItem = indexPath.row; + [self.pickerView selectRow:0 inComponent:0 animated:true]; + [self.pickerView reloadAllComponents]; +} + +#pragma mark - Picker view data source + +- (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView { + return 1; +} + +- (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { + switch (self.settingsItem) { + case SettingsItem1: + return self.test1Patterns.count; + case SettingsItem2: + return self.test2Patterns.count; + case SettingsItme3: + return self.test3Patterns.count; + default: + return 0; + } +} + +#pragma mark - Picker view delegate + +- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { + switch (self.settingsItem) { + case SettingsItem1: + return self.test1Patterns[row]; + case SettingsItem2: + return self.test2Patterns[row]; + case SettingsItme3: + return self.test3Patterns[row]; + } + + return @""; +} + +- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { + switch (self.settingsItem) { + case SettingsItem1: + self.test1 = self.test1Patterns[row]; + break; + case SettingsItem2: + self.test2 = self.test2Patterns[row]; + break; + case SettingsItme3: + self.test3 = self.test3Patterns[row]; + break; + } + + [self.tableView reloadData]; +} + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ + ViewController *viewController = segue.destinationViewController; + viewController.test1 = self.test1; + viewController.test2 = self.test2; + viewController.test3 = self.test3; +} + +@end diff --git a/OneTimePasswordExample/SettingTableViewCell.storyboard b/OneTimePasswordExample/SettingTableViewCell.storyboard new file mode 100644 index 0000000..dd79351 --- /dev/null +++ b/OneTimePasswordExample/SettingTableViewCell.storyboard @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OneTimePasswordExample/SettingTableViewCell.xib b/OneTimePasswordExample/SettingTableViewCell.xib new file mode 100644 index 0000000..631227f --- /dev/null +++ b/OneTimePasswordExample/SettingTableViewCell.xib @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OneTimePasswordExample/SettingsTableViewCell.h b/OneTimePasswordExample/SettingsTableViewCell.h new file mode 100644 index 0000000..84946b0 --- /dev/null +++ b/OneTimePasswordExample/SettingsTableViewCell.h @@ -0,0 +1,19 @@ +// +// SettingTableViewCell.h +// OneTimePasswordExample +// +// Created by MaiNakagami on 2021/09/30. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface SettingsTableViewCell : UITableViewCell + +@property (weak, nonatomic) IBOutlet UILabel *titleLabel; +@property (weak, nonatomic) IBOutlet UILabel *valueLabel; + +@end + +NS_ASSUME_NONNULL_END diff --git a/OneTimePasswordExample/SettingsTableViewCell.m b/OneTimePasswordExample/SettingsTableViewCell.m new file mode 100644 index 0000000..40b44d4 --- /dev/null +++ b/OneTimePasswordExample/SettingsTableViewCell.m @@ -0,0 +1,23 @@ +// +// SettingTableViewCell.m +// OneTimePasswordExample +// +// Created by MaiNakagami on 2021/09/30. +// + +#import "SettingsTableViewCell.h" + +@implementation SettingsTableViewCell + +- (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 diff --git a/OneTimePasswordExample/ViewController.h b/OneTimePasswordExample/ViewController.h index 3cfd969..0157d2d 100644 --- a/OneTimePasswordExample/ViewController.h +++ b/OneTimePasswordExample/ViewController.h @@ -8,7 +8,9 @@ #import @interface ViewController : UIViewController - +@property (nonatomic) NSString *test1; +@property (nonatomic) NSString *test2; +@property (nonatomic) NSString *test3; @end diff --git a/OneTimePasswordExample/ViewController.m b/OneTimePasswordExample/ViewController.m index 3dbfaaa..cb7b102 100644 --- a/OneTimePasswordExample/ViewController.m +++ b/OneTimePasswordExample/ViewController.m @@ -7,6 +7,7 @@ #import "ViewController.h" #import "OneTimePassword.h" +#import "SettingController.h" #import #import @@ -16,6 +17,7 @@ @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *oneTimePasswordLabel; @property (weak, nonatomic) IBOutlet UAProgressView *oneTimePasswordProgressView; +@property (weak, nonatomic) IBOutlet UILabel *test; @property (nonatomic, assign) CGFloat localProgress; @@ -30,6 +32,7 @@ - (void)viewDidLoad { [self initOneTimePasswordView]; [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(updateOneTimePasswordView:) userInfo:nil repeats:YES]; + } - (void)initOneTimePasswordToken { @@ -39,7 +42,8 @@ - (void)initOneTimePasswordToken { NSData *secretData = [NSData dataWithBase32String:secretString]; - self.token = [OTPToken tokenWithType:OTPTokenTypeTimer secret:secretData name:name issuer:issuer ]; + self.token = [OTPToken tokenWithType:OTPTokenTypeTimer secret:secretData name:name issuer:issuer]; + self.token.algorithm = @"OTPAlgorithm algorithm"; } - (void)initOneTimePasswordView { diff --git a/Podfile.lock b/Podfile.lock index 4a2419f..ff91346 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -21,4 +21,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 07904d67eb13b9136ed0ec5bcece3229fe2f25a7 -COCOAPODS: 1.10.2 +COCOAPODS: 1.11.0 diff --git a/Setting Controller.m b/Setting Controller.m new file mode 100644 index 0000000..4511269 --- /dev/null +++ b/Setting Controller.m @@ -0,0 +1,8 @@ +// +// Setting Controller.m +// OneTimePasswordExample +// +// Created by 岡慶太郎 on 2021/09/28. +// + +#import