Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GeliBusinessPlatform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ljy
GeliBusinessPlatform
Commits
c61c367e
Commit
c61c367e
authored
Feb 27, 2021
by
lujunye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
蓝牙接入完成
parent
37b07214
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
189 additions
and
6 deletions
+189
-6
GeliBusinessPlatform.xcworkspace/xcuserdata/junyelu.xcuserdatad/UserInterfaceState.xcuserstate
...erdata/junyelu.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
GeliBusinessPlatform/AppDelegate.swift
GeliBusinessPlatform/AppDelegate.swift
+2
-2
GeliBusinessPlatform/Define/Bridge_Header.h
GeliBusinessPlatform/Define/Bridge_Header.h
+1
-1
GeliBusinessPlatform/ViewController/蓝牙连接/BtViewController.m
GeliBusinessPlatform/ViewController/蓝牙连接/BtViewController.m
+178
-2
GeliBusinessPlatform/ViewController/蓝牙连接/BtViewController.xib
...BusinessPlatform/ViewController/蓝牙连接/BtViewController.xib
+8
-1
No files found.
GeliBusinessPlatform.xcworkspace/xcuserdata/junyelu.xcuserdatad/UserInterfaceState.xcuserstate
View file @
c61c367e
No preview for this file type
GeliBusinessPlatform/AppDelegate.swift
View file @
c61c367e
...
...
@@ -40,13 +40,13 @@ import ESTabBarController_swift
@UIApplicationMain
class
AppDelegate
:
UIResponder
,
UIApplicationDelegate
,
loginDelegate
,
UITabBarControllerDelegate
,
JPUSHRegisterDelegate
{
var
blueToothVC
:
UI
ViewController
!
var
blueToothVC
:
Bt
ViewController
!
var
window
:
UIWindow
?
func
application
(
_
application
:
UIApplication
,
didFinishLaunchingWithOptions
launchOptions
:
[
UIApplication
.
LaunchOptionsKey
:
Any
]?)
->
Bool
{
// 启动图,调整展示时间为3秒
Thread
.
sleep
(
forTimeInterval
:
2.0
)
blueToothVC
=
UI
ViewController
()
blueToothVC
=
Bt
ViewController
()
let
UserToken
=
UserDefaults
.
standard
.
value
(
forKey
:
"user_token"
)
if
UserToken
==
nil
{
...
...
GeliBusinessPlatform/Define/Bridge_Header.h
View file @
c61c367e
...
...
@@ -29,5 +29,5 @@
#import "HLBLEManager.h"
#import "SVProgressHUD.h"
#import "BtViewController.h"
#endif
/* Bridge_Header_h */
GeliBusinessPlatform/ViewController/蓝牙连接/BtViewController.m
View file @
c61c367e
...
...
@@ -9,21 +9,32 @@
#import "BtViewController.h"
#import "HLBLEManager.h"
#import "SVProgressHUD.h"
@interface
BtViewController
()
#import "HLPrinter.h"
#import "UIWebView+UIImage.h"
#import "Bt_Cell.h"
@interface
BtViewController
()
<
UITableViewDelegate
,
UITableViewDataSource
>
@property
(
weak
,
nonatomic
)
IBOutlet
UITableView
*
tableView
;
@property
(
strong
,
nonatomic
)
NSMutableArray
*
deviceArray
;
/**< 蓝牙设备个数 */
@property
(
strong
,
nonatomic
)
NSMutableArray
*
selectArray
;
//选择蓝牙
@property
(
copy
,
nonatomic
)
void
(
^
printBlock
)(
HLPrinter
*
printer
);
@property
(
nonatomic
,
strong
)
HLBLEManager
*
manager
;
@end
@implementation
BtViewController
-
(
IBAction
)
backAction
:(
id
)
sender
{
[
self
.
navigationController
popViewControllerAnimated
:
YES
];
}
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
// Do any additional setup after loading the view from its nib.
_deviceArray
=
[[
NSMutableArray
alloc
]
init
];
_selectArray
=
[[
NSMutableArray
alloc
]
init
];
_tableView
.
rowHeight
=
44
;
[
_tableView
registerNib
:[
UINib
nibWithNibName
:
@"Bt_Cell"
bundle
:
NULL
]
forCellReuseIdentifier
:
@"Bt_Cell"
];
HLBLEManager
*
manager
=
[
HLBLEManager
sharedInstance
];
__weak
HLBLEManager
*
weakManager
=
manager
;
manager
.
stateUpdateBlock
=
^
(
CBCentralManager
*
central
)
{
...
...
@@ -93,6 +104,171 @@
};
}
#pragma mark - UITableViewDataSource
-
(
NSInteger
)
numberOfSectionsInTableView
:(
UITableView
*
)
tableView
{
return
2
;
}
-
(
NSInteger
)
tableView
:(
UITableView
*
)
tableView
numberOfRowsInSection
:(
NSInteger
)
section
{
if
(
section
==
0
)
{
return
_selectArray
.
count
;
}
return
_deviceArray
.
count
;
}
-
(
void
)
tableView
:(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
[
self
.
selectArray
removeAllObjects
];
if
(
indexPath
.
section
==
1
){
NSDictionary
*
dict
=
[
self
.
deviceArray
objectAtIndex
:
indexPath
.
row
];
CBPeripheral
*
peripheral
=
dict
[
@"peripheral"
];
[
self
.
selectArray
addObject
:
peripheral
];
[
self
loadBLEInfo
];
[
tableView
reloadData
];
}
else
{
[
_manager
cancelPeripheralConnection
];
}
}
-
(
UITableViewCell
*
)
tableView
:(
UITableView
*
)
tableView
cellForRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
Bt_Cell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
@"Bt_Cell"
];
NSDictionary
*
dict
=
[
self
.
deviceArray
objectAtIndex
:
indexPath
.
row
];
CBPeripheral
*
peripherral
=
dict
[
@"peripheral"
];
cell
.
statusImg
.
hidden
=
YES
;
if
(
indexPath
.
section
==
0
)
{
cell
.
statusImg
.
hidden
=
NO
;
}
cell
.
title_lbl
.
text
=
peripherral
.
name
;
return
cell
;
}
-
(
CGFloat
)
tableView
:(
UITableView
*
)
tableView
heightForHeaderInSection
:(
NSInteger
)
section
{
return
46
;
}
-
(
CGFloat
)
tableView
:(
UITableView
*
)
tableView
heightForFooterInSection
:(
NSInteger
)
section
{
return
46
;
}
-
(
UIView
*
)
tableView
:(
UITableView
*
)
tableView
viewForHeaderInSection
:(
NSInteger
)
section
{
UIView
*
view
=
[[
UIView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
view
.
bounds
.
size
.
width
,
46
)];
view
.
backgroundColor
=
[
UIColor
colorNamed
:
@"app底色"
];
UILabel
*
lbl
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
15
,
0
,
self
.
view
.
bounds
.
size
.
width
,
46
)];
lbl
.
font
=
[
UIFont
boldSystemFontOfSize
:
15
];
lbl
.
textColor
=
[
UIColor
colorNamed
:
@"灰色字体颜色"
];
[
view
addSubview
:
lbl
];
switch
(
section
)
{
case
0
:
{
lbl
.
text
=
@"已连接设备"
;
}
break
;
default:
{
lbl
.
text
=
@"未连接设备"
;
}
break
;
}
return
view
;
}
-
(
UIView
*
)
tableView
:(
UITableView
*
)
tableView
viewForFooterInSection
:(
NSInteger
)
section
{
UIView
*
view
=
[[
UIView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
view
.
bounds
.
size
.
width
,
46
)];
view
.
backgroundColor
=
[
UIColor
colorNamed
:
@"app底色"
];
UILabel
*
lbl
=
[[
UILabel
alloc
]
initWithFrame
:
CGRectMake
(
15
,
0
,
self
.
view
.
bounds
.
size
.
width
,
46
)];
lbl
.
font
=
[
UIFont
boldSystemFontOfSize
:
11
];
lbl
.
textColor
=
[
UIColor
colorNamed
:
@"灰色字体颜色"
];
[
view
addSubview
:
lbl
];
switch
(
section
)
{
case
0
:
{
lbl
.
text
=
@"选择已经连接的设备作为默认打印设备"
;
}
break
;
default:
{
lbl
.
text
=
@"选择设备进行连接"
;
}
break
;
}
return
view
;
}
// UIWebView *webView = [[UIWebView alloc]init];
// webView.delegate = self;
// [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://c.gelifood.com/market/src/views/Order/codeDetail.html?order_id=12767"]]];
//- (void)webViewDidFinishLoad:(UIWebView *)webView
//{
// HLPrinter *printer = [[HLPrinter alloc] init];
// UIImage *image = [webView imageForWebView];
// [printer appendImage:image alignment:HLTextAlignmentLeft maxWidth:450];
//
// if (_printBlock) {
// _printBlock(printer);
// }
//}
-
(
void
)
loadBLEInfo
{
CBPeripheral
*
perpheral
=
_selectArray
.
firstObject
;
HLBLEManager
*
manager
=
[
HLBLEManager
sharedInstance
];
_manager
=
manager
;
[
manager
connectPeripheral
:
perpheral
connectOptions:
@{
CBConnectPeripheralOptionNotifyOnDisconnectionKey
:
@
(
YES
)}
stopScanAfterConnected:
YES
servicesOptions:
nil
characteristicsOptions:
nil
completeBlock:
^
(
HLOptionStage
stage
,
CBPeripheral
*
peripheral
,
CBService
*
service
,
CBCharacteristic
*
character
,
NSError
*
error
)
{
switch
(
stage
)
{
case
HLOptionStageConnection
:
{
if
(
error
)
{
[
SVProgressHUD
showErrorWithStatus
:
@"连接失败"
];
}
else
{
[
SVProgressHUD
showSuccessWithStatus
:
@"连接成功"
];
}
break
;
}
case
HLOptionStageSeekServices
:
{
if
(
error
)
{
// [SVProgressHUD showSuccessWithStatus:@"查找服务失败"];
}
else
{
// [SVProgressHUD showSuccessWithStatus:@"查找服务成功"];
}
break
;
}
case
HLOptionStageSeekCharacteristics
:
{
// 该block会返回多次,每一个服务返回一次
if
(
error
)
{
NSLog
(
@"查找特性失败"
);
}
else
{
NSLog
(
@"查找特性成功"
);
[
_tableView
reloadData
];
}
break
;
}
case
HLOptionStageSeekdescriptors
:
{
// 该block会返回多次,每一个特性返回一次
if
(
error
)
{
NSLog
(
@"查找特性的描述失败"
);
}
else
{
// NSLog(@"查找特性的描述成功");
}
break
;
}
default:
break
;
}
}];
}
@end
GeliBusinessPlatform/ViewController/蓝牙连接/BtViewController.xib
View file @
c61c367e
...
...
@@ -45,6 +45,9 @@
<constraint
firstAttribute=
"width"
relation=
"greaterThanOrEqual"
constant=
"46"
id=
"BLS-5O-HaU"
/>
<constraint
firstAttribute=
"width"
constant=
"46"
id=
"hrV-57-cL5"
/>
</constraints>
<connections>
<action
selector=
"backAction:"
destination=
"-1"
eventType=
"touchUpInside"
id=
"JMm-Xi-knv"
/>
</connections>
</button>
</subviews>
<color
key=
"backgroundColor"
systemColor=
"systemBackgroundColor"
/>
...
...
@@ -88,7 +91,8 @@
</view>
<tableView
clipsSubviews=
"YES"
contentMode=
"scaleToFill"
alwaysBounceVertical=
"YES"
style=
"plain"
separatorStyle=
"default"
rowHeight=
"-1"
estimatedRowHeight=
"-1"
sectionHeaderHeight=
"28"
sectionFooterHeight=
"28"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"1gI-Ls-VbE"
>
<rect
key=
"frame"
x=
"0.0"
y=
"108"
width=
"414"
height=
"705"
/>
<color
key=
"backgroundColor"
systemColor=
"systemBackgroundColor"
/>
<color
key=
"backgroundColor"
name=
"app底色"
/>
<color
key=
"tintColor"
white=
"0.0"
alpha=
"0.0"
colorSpace=
"custom"
customColorSpace=
"genericGamma22GrayColorSpace"
/>
<connections>
<outlet
property=
"dataSource"
destination=
"-1"
id=
"d6a-dm-laN"
/>
<outlet
property=
"delegate"
destination=
"-1"
id=
"KQt-4I-gy6"
/>
...
...
@@ -115,6 +119,9 @@
<resources>
<image
name=
"fanhui"
width=
"18"
height=
"35"
/>
<image
name=
"guanbi"
width=
"37"
height=
"18"
/>
<namedColor
name=
"app底色"
>
<color
red=
"0.94509803921568625"
green=
"0.94509803921568625"
blue=
"0.94509803921568625"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
</namedColor>
<namedColor
name=
"标题字颜色"
>
<color
red=
"0.18000000715255737"
green=
"0.18000000715255737"
blue=
"0.18000000715255737"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
</namedColor>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment