diff --git a/ChatSDK.podspec b/ChatSDK.podspec index 4dd39365..66f0ad87 100644 --- a/ChatSDK.podspec +++ b/ChatSDK.podspec @@ -10,65 +10,66 @@ Pod::Spec.new do |s| s.platform = :ios, '8.0' s.requires_arc = true - + s.default_subspec = 'UI' - + s.subspec 'Core' do |core| - core.source_files = ['ChatSDKCore/Classes/**/*'] - core.resource_bundles = { - 'ChatCore' => ['ChatSDKCore/Assets/**/*'] - } + core.source_files = ['ChatSDKCore/Classes/**/*'] + core.resource_bundles = { + 'ChatCore' => ['ChatSDKCore/Assets/**/*'] + } + + core.dependency 'RXPromise', '~> 1.0' + # core.dependency 'PromiseKit' + core.dependency 'Reachability', '~> 3.0' + core.dependency 'AFNetworking', '~>3.1.0' - core.dependency 'RXPromise', '~> 1.0' - # core.dependency 'PromiseKit' - core.dependency 'Reachability', '~> 3.0' - core.dependency 'AFNetworking', '~>3.1.0' + # core.frameworks = 'CoreLocation' + core.frameworks = 'SafariServices' -# core.frameworks = 'CoreLocation' - core.frameworks = 'SafariServices' - end s.subspec 'CoreData' do |cd| - - cd.source_files = ['ChatSDKCoreData/Classes/**/*'] + + cd.source_files = ['ChatSDKCoreData/Classes/**/*'] cd.resource_bundles = { 'ChatCoreData' => ['ChatSDKCoreData/Assets/**/*'] - } - + } + cd.frameworks = 'UIKit', 'CoreData' cd.dependency 'ChatSDK/Core' - + end - s.subspec 'UI' do |ui| - - ui.source_files = ['ChatSDKUI/Classes/**/*'] - ui.resource_bundles = { - 'ChatUI' => ['ChatSDKUI/Assets/**/*', 'ChatSDKUI/Interface/**/*'] - } - - ui.dependency 'MBProgressHUD', '~> 1.0' - ui.dependency 'VENTokenField', '~> 2.0' - ui.dependency 'SDWebImage', '~> 4.0' - ui.dependency 'StaticDataTableViewController', '~> 2.0' - ui.dependency 'CountryPicker', '~> 1.0' - ui.dependency 'DateTools', '~> 1.0' - ui.dependency 'TOCropViewController', '~> 2.0' - ui.dependency 'Hakawai', '~> 5.0.0' - ui.dependency 'ChatSDKKeepLayout' - ui.dependency 'Toast', '~>4.0.0' - - ui.dependency 'ChatSDK/CoreData' - - ui.frameworks = 'CoreLocation' - +s.subspec 'UI' do |ui| + + ui.source_files = ['ChatSDKUI/Classes/**/*'] + ui.resource_bundles = { + 'ChatUI' => ['ChatSDKUI/Assets/**/*', 'ChatSDKUI/Interface/**/*'] + } + + ui.dependency 'MBProgressHUD', '~> 1.0' + ui.dependency 'VENTokenField', '~> 2.0' + ui.dependency 'SDWebImage', '~> 4.0' + ui.dependency 'StaticDataTableViewController', '~> 2.0' + ui.dependency 'CountryPicker', '~> 1.0' + ui.dependency 'DateTools', '~> 1.0' + ui.dependency 'TOCropViewController', '~> 2.0' + ui.dependency 'Hakawai', '~> 5.0.0' + ui.dependency 'ChatSDKKeepLayout' + ui.dependency 'Toast', '~>4.0.0' + ui.dependency 'Mapbox-iOS-SDK', '~> 3.7' + + ui.dependency 'ChatSDK/CoreData' + + ui.frameworks = 'CoreLocation' + end # s.subspec 'FirebaseAdapter' do |fb| # -# fb.source_files = ['ChatSDKFirebase/FirebaseNetworkAdapter/Classes/**/*'] +# fb.source_files = ['ChatSDKFirebase/FirebaseNetworkAdapter/Classes/**/*'] # # fb.dependency 'Firebase/Core' # fb.dependency 'Firebase/Auth' @@ -78,7 +79,7 @@ Pod::Spec.new do |s| # # # fb.vendored_frameworks = "ChatSDKFirebaseAdapter/Frameworks/FirebaseAdapter.framework" # -# fb.dependency 'ChatSDK/Core' +# fb.dependency 'ChatSDK/Core' # # end diff --git a/ChatSDKUI/Classes/Actions/BSelectLocationAction.h b/ChatSDKUI/Classes/Actions/BSelectLocationAction.h index ba01e6fb..da6f4f91 100644 --- a/ChatSDKUI/Classes/Actions/BSelectLocationAction.h +++ b/ChatSDKUI/Classes/Actions/BSelectLocationAction.h @@ -1,6 +1,6 @@ // // BSelectLocationAction.h -// AFNetworking +// ChatSDK // // Created by Ben on 12/11/17. // @@ -8,12 +8,12 @@ #import #import #import +#import @protocol CLLocationManagerDelegate; -@interface BSelectLocationAction : NSObject { - CLLocationManager * _locationManager; - RXPromise * _promise; -} +@interface BSelectLocationAction : NSObject + +- (instancetype)initWithViewController:(UIViewController *)controller; @end diff --git a/ChatSDKUI/Classes/Actions/BSelectLocationAction.m b/ChatSDKUI/Classes/Actions/BSelectLocationAction.m index a85042ab..74c6b770 100644 --- a/ChatSDKUI/Classes/Actions/BSelectLocationAction.m +++ b/ChatSDKUI/Classes/Actions/BSelectLocationAction.m @@ -1,6 +1,6 @@ // // BSelectLocationAction.m -// AFNetworking +// ChatSDK // // Created by Ben on 12/11/17. // @@ -8,47 +8,46 @@ #import "BSelectLocationAction.h" #import +@interface BSelectLocationAction() { + RXPromise * _promise; + __weak UIViewController * _controller; + UINavigationController * _navController; + BLocationPickerController * _picker; +} +@end + @implementation BSelectLocationAction --(RXPromise *) execute { - - if(_promise) { - return _promise; - } - else { - _promise = [RXPromise new]; +- (instancetype)initWithViewController:(UIViewController *)controller { + if ((self = [self init])) { + _controller = controller; } - - if(!_locationManager) { - _locationManager = [[CLLocationManager alloc] init]; - - if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined && - [_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { - [_locationManager requestWhenInUseAuthorization]; - } - - _locationManager.delegate = self; - _locationManager.distanceFilter = kCLDistanceFilterNone; - _locationManager.desiredAccuracy = kCLLocationAccuracyBest; - } - [_locationManager startUpdatingLocation]; - - return _promise; + return self; } -- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { +- (RXPromise *)execute { + _promise = [RXPromise new]; - [manager stopUpdatingLocation]; - if(_locationManager) { - _locationManager = nil; - - CLLocation * location = locations.lastObject; - [_promise resolveWithResult:location]; + if (!_picker) { + _picker = [[BLocationPickerController alloc] init]; + _picker.delegate = self; } - if(_promise) { - [_promise resolveWithResult: Nil]; + + if (!_navController) { + _navController = [[UINavigationController alloc] initWithRootViewController:_picker]; } - _promise = Nil; + + [_controller presentViewController:_navController animated:YES completion:nil]; + + return _promise; +} + +- (void)locationPickerController:(id)locationPicker didSelectLocation:(CLLocation *)location { + [_promise resolveWithResult:location]; +} + +- (void)locationPickerControllerDidCancel:(id)locationPicker { + [_promise rejectWithReason:nil]; } @end diff --git a/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.h b/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.h index 66394539..906278f0 100644 --- a/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.h +++ b/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.h @@ -1,6 +1,6 @@ // // BLocationOption.h -// Pods +// ChatSDK // // Created by Benjamin Smiley-andrews on 17/12/2016. // @@ -8,11 +8,6 @@ #import -@class RXPromise; -@class BSelectLocationAction; - -@interface BLocationChatOption : BChatOption { - BSelectLocationAction * _action; -} +@interface BLocationChatOption : BChatOption @end diff --git a/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.m b/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.m index 7729891a..7ff89c35 100644 --- a/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.m +++ b/ChatSDKUI/Classes/Components/ChatOptions/BLocationChatOption.m @@ -1,6 +1,6 @@ // // BLocationOption.m -// Pods +// ChatSDK // // Created by Benjamin Smiley-andrews on 17/12/2016. // @@ -10,6 +10,13 @@ #import #import +@class BLocationPickerControllerDelegate; + +@interface BLocationChatOption() { + BSelectLocationAction * action; +} +@end + @implementation BLocationChatOption @synthesize parent; @@ -23,10 +30,11 @@ -(NSString *) title { } -(RXPromise *) execute { - if(_action == Nil) { - _action = [[BSelectLocationAction alloc] init]; + if (!action) { + action = [[BSelectLocationAction alloc] initWithViewController:self.parent.delegate.currentViewController]; } - return [_action execute].thenOnMain(^id(id location) { + + return [action execute].thenOnMain(^id(CLLocation * location) { return [self.parent.delegate sendLocationMessage:location]; }, Nil); } diff --git a/ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.h b/ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.h new file mode 100644 index 00000000..7b654f30 --- /dev/null +++ b/ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.h @@ -0,0 +1,22 @@ +// +// BLocationPickerController.h +// ChatSDK +// +// Created by Pepe Becker on 24.04.18. +// + +#import +#import + +@protocol BLocationPickerControllerDelegate + +- (void)locationPickerController:(id)locationPicker didSelectLocation:(CLLocation *)location; +- (void)locationPickerControllerDidCancel:(id)locationPicker; + +@end + +@interface BLocationPickerController : UIViewController + +@property (nonatomic, weak) id delegate; + +@end diff --git a/ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.m b/ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.m new file mode 100644 index 00000000..dab2f0fe --- /dev/null +++ b/ChatSDKUI/Classes/Components/View Controllers/BLocationPickerController.m @@ -0,0 +1,80 @@ +// +// BLocationPickerController.m +// ChatSDK +// +// Created by Pepe Becker on 24.04.18. +// + +#import "BLocationPickerController.h" +@import Mapbox; + +@interface BLocationPickerController() + +@property (nonatomic) MGLMapView * mapView; +@property (nonatomic) MGLPointAnnotation * annotation; + +@end + +@implementation BLocationPickerController + +@synthesize delegate; + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action: @selector(cancel)]; + + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action: @selector(done)]; + self.navigationItem.rightBarButtonItem.enabled = NO; + + self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds]; + self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [self.view addSubview:self.mapView]; + self.mapView.delegate = self; + + self.mapView.showsUserLocation = YES; + [self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:YES]; + + UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didRecognizeTab:)]; + tapRecognizer.delegate = self; + [self.view addGestureRecognizer:tapRecognizer]; +} + +- (void)didRecognizeTab:(UITapGestureRecognizer *)sender { + CGPoint point = [sender locationInView:self.mapView]; + CLLocationCoordinate2D coordinate = [self.mapView convertPoint:point toCoordinateFromView:self.mapView]; + + if (self.annotation) { + [self.mapView removeAnnotation:self.annotation]; + } + + self.annotation = [MGLPointAnnotation alloc]; + self.annotation.coordinate = coordinate; + [self.mapView addAnnotation:self.annotation]; + + self.navigationItem.rightBarButtonItem.enabled = YES; +} + +- (void)cancel { + [delegate locationPickerControllerDidCancel:self]; + [self dismiss]; +} + +- (void)done { + CLLocationCoordinate2D coords = self.annotation.coordinate; + CLLocation * location = [[CLLocation alloc] initWithLatitude:coords.latitude longitude:coords.longitude]; + [delegate locationPickerController:self didSelectLocation:location]; + [self dismiss]; +} + +- (void)dismiss { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +#pragma mark - UIGestureRecognizerDelegate + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer { + return YES; +} + +@end diff --git a/XcodeSwift/ChatSDKSwift.xcodeproj/project.pbxproj b/XcodeSwift/ChatSDKSwift.xcodeproj/project.pbxproj index 39cbdbf4..54a8492e 100644 --- a/XcodeSwift/ChatSDKSwift.xcodeproj/project.pbxproj +++ b/XcodeSwift/ChatSDKSwift.xcodeproj/project.pbxproj @@ -456,6 +456,8 @@ "${BUILT_PRODUCTS_DIR}/GoogleToolboxForMac/GoogleToolboxForMac.framework", "${BUILT_PRODUCTS_DIR}/Hakawai/Hakawai.framework", "${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework", + "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework", + "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM", "${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework", "${BUILT_PRODUCTS_DIR}/RXPromise/RXPromise.framework", "${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework", @@ -485,6 +487,8 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleToolboxForMac.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Hakawai.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MBProgressHUD.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework", + "${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Protobuf.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RXPromise.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework", diff --git a/XcodeSwift/ChatSDKSwift/Info.plist b/XcodeSwift/ChatSDKSwift/Info.plist index 1d9154c9..f23aea72 100644 --- a/XcodeSwift/ChatSDKSwift/Info.plist +++ b/XcodeSwift/ChatSDKSwift/Info.plist @@ -61,6 +61,8 @@ LSRequiresIPhoneOS + MGLMapboxAccessToken + pk.eyJ1IjoicGVwZWJlY2tlciIsImEiOiJjajd3OTZoN2swbWhyMnFvMG5hYm94dHh0In0.35W237Y_1f_9noUbCfTWNw NSAppTransportSecurity NSAllowsArbitraryLoads