完善二维码显示功能

This commit is contained in:
cebgcontract 2022-11-25 17:00:10 +08:00
parent 4b45e34627
commit 885a023bc4
12 changed files with 1237 additions and 42 deletions

View File

@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) UIImage* imgScan;
@property (nonatomic, copy) NSString* content;
@property (nonatomic, copy) NSString* tipTitle;
@property (nonatomic, copy) NSString* tipTxt;
@property (nonatomic, assign) BOOL autosave;
@end

View File

@ -7,12 +7,14 @@
#import "QrCodeViewController.h"
#include "LBXScanNative.h"
#include "UIUtils.h"
@interface QrCodeViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *scanImg;
@property (weak, nonatomic) IBOutlet UIView *container;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end
@ -22,6 +24,7 @@
[super viewDidLoad];
// Do any additional setup after loading the view.
[_closeBtn addTarget:self action:@selector(dismissSelf:) forControlEvents:UIControlEventTouchUpInside];
[_saveBtn addTarget:self action:@selector(saveToLibrary:) forControlEvents:UIControlEventTouchUpInside];
self.container.backgroundColor = [UIColor whiteColor];
self.container.layer.shadowOffset = CGSizeMake(0, 2);
self.container.layer.shadowRadius = 2;
@ -52,6 +55,15 @@
}
_titleLabel.text = _tipTitle;
_scanImg.image = _imgScan;
if (_tipTxt) {
_textView.text = _tipTxt;
_textView.hidden = NO;
} else {
_textView.hidden = YES;
}
_saveBtn.hidden = YES;
if (_autosave) {
[self saveToPhotoLibrary];
}
@ -69,9 +81,13 @@
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
NSLog(@"保存失败");
NSLog(@"save error");
[UIUtils showToastWithMessage: @"Error save recovery key image to System Library, Save it manually."];
_saveBtn.hidden = NO;
} else {
NSLog(@"保存成功");
NSLog(@"save success");
[UIUtils showToastWithMessage: @"Success save recovery key image to System Library."];
_saveBtn.hidden = YES;
}
}
@ -79,4 +95,8 @@
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)saveToLibrary:(UIButton *)button{
[self saveToPhotoLibrary];
}
@end

View File

@ -13,6 +13,7 @@
<connections>
<outlet property="closeBtn" destination="ARv-35-WSy" id="822-Id-lUS"/>
<outlet property="container" destination="fpG-y0-v4j" id="jpQ-po-eFA"/>
<outlet property="saveBtn" destination="Yd7-dw-3J7" id="oLe-Py-MrF"/>
<outlet property="scanImg" destination="RbQ-nc-PEN" id="RaM-Wf-FXx"/>
<outlet property="textView" destination="O4k-Xx-lNi" id="g5n-oI-kNK"/>
<outlet property="titleLabel" destination="FUd-A4-OOf" id="dt5-bR-8rI"/>
@ -24,20 +25,45 @@
<rect key="frame" x="0.0" y="0.0" width="896" height="414"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="O4k-Xx-lNi">
<rect key="frame" x="568" y="103" width="240" height="248"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="vE1-L9-g1t">
<rect key="frame" x="453" y="62" width="240" height="290"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="O4k-Xx-lNi">
<rect key="frame" x="0.0" y="0.0" width="240" height="248"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="AgP-iJ-PiA"/>
<constraint firstAttribute="height" constant="248" id="X7c-Eh-aot"/>
</constraints>
<string key="text">This QR code is only used to export account recovery private key.
1. Use CEBG client to scan the QR code to get the account recovery private key.
2. Account of ios cannot login to Andorid device.
3. Please keep your private key as safe as possible.</string>
<color key="textColor" systemColor="labelColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Yd7-dw-3J7">
<rect key="frame" x="59.5" y="259.5" width="121" height="31"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="filled" title="Save to Library"/>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="width" constant="240" id="AgP-iJ-PiA"/>
<constraint firstAttribute="height" constant="248" id="X7c-Eh-aot"/>
<constraint firstAttribute="height" constant="290" id="KM4-Td-MHi"/>
<constraint firstItem="Yd7-dw-3J7" firstAttribute="centerY" secondItem="vE1-L9-g1t" secondAttribute="centerY" constant="130" id="Mwx-qv-AhR"/>
<constraint firstItem="O4k-Xx-lNi" firstAttribute="centerY" secondItem="vE1-L9-g1t" secondAttribute="centerY" constant="-21" id="UUe-ym-vc2"/>
<constraint firstAttribute="width" constant="240" id="bHb-iY-KaN"/>
<constraint firstItem="Yd7-dw-3J7" firstAttribute="centerX" secondItem="vE1-L9-g1t" secondAttribute="centerX" id="wiI-nc-Mkt"/>
<constraint firstItem="O4k-Xx-lNi" firstAttribute="centerX" secondItem="vE1-L9-g1t" secondAttribute="centerX" id="zWh-MY-BCS"/>
</constraints>
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
<color key="textColor" systemColor="labelColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ARv-35-WSy">
<rect key="frame" x="84" y="40" width="80" height="31"/>
<rect key="frame" x="64" y="10" width="80" height="31"/>
<constraints>
<constraint firstAttribute="width" constant="80" id="0fF-Qx-qH4"/>
<constraint firstAttribute="height" constant="31" id="50h-Rz-9MN"/>
@ -47,7 +73,7 @@
<buttonConfiguration key="configuration" style="tinted" title="Close"/>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="fpG-y0-v4j">
<rect key="frame" x="318" y="62" width="260" height="290"/>
<rect key="frame" x="183" y="62" width="260" height="290"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FUd-A4-OOf">
<rect key="frame" x="111.5" y="15.5" width="37.5" height="19"/>
@ -80,12 +106,12 @@
<constraints>
<constraint firstItem="fpG-y0-v4j" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="56v-Gg-QJh"/>
<constraint firstItem="ARv-35-WSy" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" constant="-110" id="94T-iZ-mPQ"/>
<constraint firstItem="ARv-35-WSy" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="40" id="96a-om-YCg"/>
<constraint firstItem="ARv-35-WSy" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="10" id="96a-om-YCg"/>
<constraint firstItem="vE1-L9-g1t" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" constant="125" id="C7F-9t-AfG"/>
<constraint firstItem="ARv-35-WSy" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" constant="-210" id="M0S-Ry-qx7"/>
<constraint firstItem="fpG-y0-v4j" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="Pgv-CL-voZ"/>
<constraint firstItem="O4k-Xx-lNi" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" constant="20" id="T7p-OA-zZd"/>
<constraint firstItem="ARv-35-WSy" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="40" id="a7T-fb-xLU"/>
<constraint firstItem="O4k-Xx-lNi" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" constant="240" id="zwm-x2-DV7"/>
<constraint firstItem="fpG-y0-v4j" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" constant="-135" id="Pgv-CL-voZ"/>
<constraint firstItem="ARv-35-WSy" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="a7T-fb-xLU"/>
<constraint firstItem="vE1-L9-g1t" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="ahj-SA-Yj1"/>
</constraints>
<variation key="default">
<mask key="constraints">

16
Classes_cocos/UIUtils.h Normal file
View File

@ -0,0 +1,16 @@
//
// UIUtils.h
// Unity-iPhone
//
// Created by zhl on 2022/11/25.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIUtils : NSObject
+ (void)showToastWithMessage:(NSString*)message;
@end
NS_ASSUME_NONNULL_END

80
Classes_cocos/UIUtils.m Normal file
View File

@ -0,0 +1,80 @@
//
// UIUtils.m
// Unity-iPhone
//
// Created by zhl on 2022/11/25.
//
#import "UIUtils.h"
#import "UIView+Toast.h"
@implementation UIUtils
+ (void)showToastWithMessage:(NSString*)message
{
if (message == nil) {
message = @"";
}
//tip
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
[window makeToast:message
duration:2
position:CSToastPositionTop];
}
+ (UIViewController*)getTopViewController
{
return [self currentTopViewController];
}
#pragma mark- Get TOP VC
+ (UIViewController*)topRootController
{
UIViewController *topController = [[UIApplication sharedApplication].delegate.window rootViewController];
// Getting topMost ViewController
while ([topController presentedViewController])
topController = [topController presentedViewController];
// Returning topMost ViewController
return topController;
}
+ (UIViewController*)presentedWithController:(UIViewController*)vc
{
while ([vc presentedViewController])
vc = vc.presentedViewController;
return vc;
}
+ (UIViewController*)currentTopViewController
{
UIViewController *currentViewController = [self topRootController];
if ([currentViewController isKindOfClass:[UITabBarController class]]
&& ((UITabBarController*)currentViewController).selectedViewController != nil )
{
currentViewController = ((UITabBarController*)currentViewController).selectedViewController;
}
currentViewController = [self presentedWithController:currentViewController];
while ([currentViewController isKindOfClass:[UINavigationController class]]
&& [(UINavigationController*)currentViewController topViewController])
{
currentViewController = [(UINavigationController*)currentViewController topViewController];
currentViewController = [self presentedWithController:currentViewController];
}
currentViewController = [self presentedWithController:currentViewController];
return currentViewController;
}
@end

View File

@ -0,0 +1,446 @@
//
// UIView+Toast.h
// Toast
//
// Copyright (c) 2011-2017 Charles Scalesse.
//
// 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 <UIKit/UIKit.h>
extern const NSString * CSToastPositionTop;
extern const NSString * CSToastPositionCenter;
extern const NSString * CSToastPositionBottom;
@class CSToastStyle;
/**
Toast is an Objective-C category that adds toast notifications to the UIView
object class. It is intended to be simple, lightweight, and easy to use. Most
toast notifications can be triggered with a single line of code.
The `makeToast:` methods create a new view and then display it as toast.
The `showToast:` methods display any view as toast.
*/
@interface UIView (Toast)
/**
Creates and presents a new toast view with a message and displays it with the
default duration and position. Styled using the shared style.
@param message The message to be displayed
*/
- (void)makeToast:(NSString *)message;
/**
Creates and presents a new toast view with a message. Duration and position
can be set explicitly. Styled using the shared style.
@param message The message to be displayed
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
*/
- (void)makeToast:(NSString *)message
duration:(NSTimeInterval)duration
position:(id)position;
/**
Creates and presents a new toast view with a message. Duration, position, and
style can be set explicitly.
@param message The message to be displayed
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param style The style. The shared style will be used when nil
*/
- (void)makeToast:(NSString *)message
duration:(NSTimeInterval)duration
position:(id)position
style:(CSToastStyle *)style;
/**
Creates and presents a new toast view with a message, title, and image. Duration,
position, and style can be set explicitly. The completion block executes when the
toast view completes. `didTap` will be `YES` if the toast view was dismissed from
a tap.
@param message The message to be displayed
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param title The title
@param image The image
@param style The style. The shared style will be used when nil
@param completion The completion block, executed after the toast view disappears.
didTap will be `YES` if the toast view was dismissed from a tap.
*/
- (void)makeToast:(NSString *)message
duration:(NSTimeInterval)duration
position:(id)position
title:(NSString *)title
image:(UIImage *)image
style:(CSToastStyle *)style
completion:(void(^)(BOOL didTap))completion;
/**
Creates a new toast view with any combination of message, title, and image.
The look and feel is configured via the style. Unlike the `makeToast:` methods,
this method does not present the toast view automatically. One of the showToast:
methods must be used to present the resulting view.
@warning if message, title, and image are all nil, this method will return nil.
@param message The message to be displayed
@param title The title
@param image The image
@param style The style. The shared style will be used when nil
@return The newly created toast view
*/
- (UIView *)toastViewForMessage:(NSString *)message
title:(NSString *)title
image:(UIImage *)image
style:(CSToastStyle *)style;
/**
Hides the active toast. If there are multiple toasts active in a view, this method
hides the oldest toast (the first of the toasts to have been presented).
@see `hideAllToasts` to remove all active toasts from a view.
@warning This method has no effect on activity toasts. Use `hideToastActivity` to
hide activity toasts.
*/
- (void)hideToast;
/**
Hides an active toast.
@param toast The active toast view to dismiss. Any toast that is currently being displayed
on the screen is considered active.
@warning this does not clear a toast view that is currently waiting in the queue.
*/
- (void)hideToast:(UIView *)toast;
/**
Hides all active toast views and clears the queue.
*/
- (void)hideAllToasts;
/**
Hides all active toast views, with options to hide activity and clear the queue.
@param includeActivity If `true`, toast activity will also be hidden. Default is `false`.
@param clearQueue If `true`, removes all toast views from the queue. Default is `true`.
*/
- (void)hideAllToasts:(BOOL)includeActivity clearQueue:(BOOL)clearQueue;
/**
Removes all toast views from the queue. This has no effect on toast views that are
active. Use `hideAllToasts` to hide the active toasts views and clear the queue.
*/
- (void)clearToastQueue;
/**
Creates and displays a new toast activity indicator view at a specified position.
@warning Only one toast activity indicator view can be presented per superview. Subsequent
calls to `makeToastActivity:` will be ignored until hideToastActivity is called.
@warning `makeToastActivity:` works independently of the showToast: methods. Toast activity
views can be presented and dismissed while toast views are being displayed. `makeToastActivity:`
has no effect on the queueing behavior of the showToast: methods.
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
*/
- (void)makeToastActivity:(id)position;
/**
Dismisses the active toast activity indicator view.
*/
- (void)hideToastActivity;
/**
Displays any view as toast using the default duration and position.
@param toast The view to be displayed as toast
*/
- (void)showToast:(UIView *)toast;
/**
Displays any view as toast at a provided position and duration. The completion block
executes when the toast view completes. `didTap` will be `YES` if the toast view was
dismissed from a tap.
@param toast The view to be displayed as toast
@param duration The notification duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param completion The completion block, executed after the toast view disappears.
didTap will be `YES` if the toast view was dismissed from a tap.
*/
- (void)showToast:(UIView *)toast
duration:(NSTimeInterval)duration
position:(id)position
completion:(void(^)(BOOL didTap))completion;
@end
/**
`CSToastStyle` instances define the look and feel for toast views created via the
`makeToast:` methods as well for toast views created directly with
`toastViewForMessage:title:image:style:`.
@warning `CSToastStyle` offers relatively simple styling options for the default
toast view. If you require a toast view with more complex UI, it probably makes more
sense to create your own custom UIView subclass and present it with the `showToast:`
methods.
*/
@interface CSToastStyle : NSObject
/**
The background color. Default is `[UIColor blackColor]` at 80% opacity.
*/
@property (strong, nonatomic) UIColor *backgroundColor;
/**
The title color. Default is `[UIColor whiteColor]`.
*/
@property (strong, nonatomic) UIColor *titleColor;
/**
The message color. Default is `[UIColor whiteColor]`.
*/
@property (strong, nonatomic) UIColor *messageColor;
/**
A percentage value from 0.0 to 1.0, representing the maximum width of the toast
view relative to it's superview. Default is 0.8 (80% of the superview's width).
*/
@property (assign, nonatomic) CGFloat maxWidthPercentage;
/**
A percentage value from 0.0 to 1.0, representing the maximum height of the toast
view relative to it's superview. Default is 0.8 (80% of the superview's height).
*/
@property (assign, nonatomic) CGFloat maxHeightPercentage;
/**
The spacing from the horizontal edge of the toast view to the content. When an image
is present, this is also used as the padding between the image and the text.
Default is 10.0.
*/
@property (assign, nonatomic) CGFloat horizontalPadding;
/**
The spacing from the vertical edge of the toast view to the content. When a title
is present, this is also used as the padding between the title and the message.
Default is 10.0.
*/
@property (assign, nonatomic) CGFloat verticalPadding;
/**
The corner radius. Default is 10.0.
*/
@property (assign, nonatomic) CGFloat cornerRadius;
/**
The title font. Default is `[UIFont boldSystemFontOfSize:16.0]`.
*/
@property (strong, nonatomic) UIFont *titleFont;
/**
The message font. Default is `[UIFont systemFontOfSize:16.0]`.
*/
@property (strong, nonatomic) UIFont *messageFont;
/**
The title text alignment. Default is `NSTextAlignmentLeft`.
*/
@property (assign, nonatomic) NSTextAlignment titleAlignment;
/**
The message text alignment. Default is `NSTextAlignmentLeft`.
*/
@property (assign, nonatomic) NSTextAlignment messageAlignment;
/**
The maximum number of lines for the title. The default is 0 (no limit).
*/
@property (assign, nonatomic) NSInteger titleNumberOfLines;
/**
The maximum number of lines for the message. The default is 0 (no limit).
*/
@property (assign, nonatomic) NSInteger messageNumberOfLines;
/**
Enable or disable a shadow on the toast view. Default is `NO`.
*/
@property (assign, nonatomic) BOOL displayShadow;
/**
The shadow color. Default is `[UIColor blackColor]`.
*/
@property (strong, nonatomic) UIColor *shadowColor;
/**
A value from 0.0 to 1.0, representing the opacity of the shadow.
Default is 0.8 (80% opacity).
*/
@property (assign, nonatomic) CGFloat shadowOpacity;
/**
The shadow radius. Default is 6.0.
*/
@property (assign, nonatomic) CGFloat shadowRadius;
/**
The shadow offset. The default is `CGSizeMake(4.0, 4.0)`.
*/
@property (assign, nonatomic) CGSize shadowOffset;
/**
The image size. The default is `CGSizeMake(80.0, 80.0)`.
*/
@property (assign, nonatomic) CGSize imageSize;
/**
The size of the toast activity view when `makeToastActivity:` is called.
Default is `CGSizeMake(100.0, 100.0)`.
*/
@property (assign, nonatomic) CGSize activitySize;
/**
The fade in/out animation duration. Default is 0.2.
*/
@property (assign, nonatomic) NSTimeInterval fadeDuration;
/**
Creates a new instance of `CSToastStyle` with all the default values set.
*/
- (instancetype)initWithDefaultStyle NS_DESIGNATED_INITIALIZER;
/**
@warning Only the designated initializer should be used to create
an instance of `CSToastStyle`.
*/
- (instancetype)init NS_UNAVAILABLE;
@end
/**
`CSToastManager` provides general configuration options for all toast
notifications. Backed by a singleton instance.
*/
@interface CSToastManager : NSObject
/**
Sets the shared style on the singleton. The shared style is used whenever
a `makeToast:` method (or `toastViewForMessage:title:image:style:`) is called
with with a nil style. By default, this is set to `CSToastStyle`'s default
style.
@param sharedStyle the shared style
*/
+ (void)setSharedStyle:(CSToastStyle *)sharedStyle;
/**
Gets the shared style from the singlton. By default, this is
`CSToastStyle`'s default style.
@return the shared style
*/
+ (CSToastStyle *)sharedStyle;
/**
Enables or disables tap to dismiss on toast views. Default is `YES`.
@param tapToDismissEnabled YES or NO
*/
+ (void)setTapToDismissEnabled:(BOOL)tapToDismissEnabled;
/**
Returns `YES` if tap to dismiss is enabled, otherwise `NO`.
Default is `YES`.
@return BOOL YES or NO
*/
+ (BOOL)isTapToDismissEnabled;
/**
Enables or disables queueing behavior for toast views. When `YES`,
toast views will appear one after the other. When `NO`, multiple Toast
views will appear at the same time (potentially overlapping depending
on their positions). This has no effect on the toast activity view,
which operates independently of normal toast views. Default is `NO`.
@param queueEnabled YES or NO
*/
+ (void)setQueueEnabled:(BOOL)queueEnabled;
/**
Returns `YES` if the queue is enabled, otherwise `NO`.
Default is `NO`.
@return BOOL
*/
+ (BOOL)isQueueEnabled;
/**
Sets the default duration. Used for the `makeToast:` and
`showToast:` methods that don't require an explicit duration.
Default is 3.0.
@param duration The toast duration
*/
+ (void)setDefaultDuration:(NSTimeInterval)duration;
/**
Returns the default duration. Default is 3.0.
@return duration The toast duration
*/
+ (NSTimeInterval)defaultDuration;
/**
Sets the default position. Used for the `makeToast:` and
`showToast:` methods that don't require an explicit position.
Default is `CSToastPositionBottom`.
@param position The default center point. Can be one of the predefined
CSToastPosition constants or a `CGPoint` wrapped in an `NSValue` object.
*/
+ (void)setDefaultPosition:(id)position;
/**
Returns the default toast position. Default is `CSToastPositionBottom`.
@return position The default center point. Will be one of the predefined
CSToastPosition constants or a `CGPoint` wrapped in an `NSValue` object.
*/
+ (id)defaultPosition;
@end

View File

@ -0,0 +1,586 @@
//
// UIView+Toast.m
// Toast
//
// Copyright (c) 2011-2017 Charles Scalesse.
//
// 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 "UIView+Toast.h"
#import <QuartzCore/QuartzCore.h>
#import <objc/runtime.h>
// Positions
NSString * CSToastPositionTop = @"CSToastPositionTop";
NSString * CSToastPositionCenter = @"CSToastPositionCenter";
NSString * CSToastPositionBottom = @"CSToastPositionBottom";
// Keys for values associated with toast views
static const NSString * CSToastTimerKey = @"CSToastTimerKey";
static const NSString * CSToastDurationKey = @"CSToastDurationKey";
static const NSString * CSToastPositionKey = @"CSToastPositionKey";
static const NSString * CSToastCompletionKey = @"CSToastCompletionKey";
// Keys for values associated with self
static const NSString * CSToastActiveKey = @"CSToastActiveKey";
static const NSString * CSToastActivityViewKey = @"CSToastActivityViewKey";
static const NSString * CSToastQueueKey = @"CSToastQueueKey";
@interface UIView (ToastPrivate)
/**
These private methods are being prefixed with "cs_" to reduce the likelihood of non-obvious
naming conflicts with other UIView methods.
@discussion Should the public API also use the cs_ prefix? Technically it should, but it
results in code that is less legible. The current public method names seem unlikely to cause
conflicts so I think we should favor the cleaner API for now.
*/
- (void)cs_showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)position;
- (void)cs_hideToast:(UIView *)toast;
- (void)cs_hideToast:(UIView *)toast fromTap:(BOOL)fromTap;
- (void)cs_toastTimerDidFinish:(NSTimer *)timer;
- (void)cs_handleToastTapped:(UITapGestureRecognizer *)recognizer;
- (CGPoint)cs_centerPointForPosition:(id)position withToast:(UIView *)toast;
- (NSMutableArray *)cs_toastQueue;
@end
@implementation UIView (Toast)
#pragma mark - Make Toast Methods
- (void)makeToast:(NSString *)message {
[self makeToast:message duration:[CSToastManager defaultDuration] position:[CSToastManager defaultPosition] style:nil];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position {
[self makeToast:message duration:duration position:position style:nil];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position style:(CSToastStyle *)style {
UIView *toast = [self toastViewForMessage:message title:nil image:nil style:style];
[self showToast:toast duration:duration position:position completion:nil];
}
- (void)makeToast:(NSString *)message duration:(NSTimeInterval)duration position:(id)position title:(NSString *)title image:(UIImage *)image style:(CSToastStyle *)style completion:(void(^)(BOOL didTap))completion {
UIView *toast = [self toastViewForMessage:message title:title image:image style:style];
[self showToast:toast duration:duration position:position completion:completion];
}
#pragma mark - Show Toast Methods
- (void)showToast:(UIView *)toast {
[self showToast:toast duration:[CSToastManager defaultDuration] position:[CSToastManager defaultPosition] completion:nil];
}
- (void)showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)position completion:(void(^)(BOOL didTap))completion {
// sanity
if (toast == nil) return;
// store the completion block on the toast view
objc_setAssociatedObject(toast, &CSToastCompletionKey, completion, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if ([CSToastManager isQueueEnabled] && [self.cs_activeToasts count] > 0) {
// we're about to queue this toast view so we need to store the duration and position as well
objc_setAssociatedObject(toast, &CSToastDurationKey, @(duration), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(toast, &CSToastPositionKey, position, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// enqueue
[self.cs_toastQueue addObject:toast];
} else {
// present
[self cs_showToast:toast duration:duration position:position];
}
}
#pragma mark - Hide Toast Methods
- (void)hideToast {
[self hideToast:[[self cs_activeToasts] firstObject]];
}
- (void)hideToast:(UIView *)toast {
// sanity
if (!toast || ![[self cs_activeToasts] containsObject:toast]) return;
[self cs_hideToast:toast];
}
- (void)hideAllToasts {
[self hideAllToasts:NO clearQueue:YES];
}
- (void)hideAllToasts:(BOOL)includeActivity clearQueue:(BOOL)clearQueue {
if (clearQueue) {
[self clearToastQueue];
}
for (UIView *toast in [self cs_activeToasts]) {
[self hideToast:toast];
}
if (includeActivity) {
[self hideToastActivity];
}
}
- (void)clearToastQueue {
[[self cs_toastQueue] removeAllObjects];
}
#pragma mark - Private Show/Hide Methods
- (void)cs_showToast:(UIView *)toast duration:(NSTimeInterval)duration position:(id)position {
toast.center = [self cs_centerPointForPosition:position withToast:toast];
toast.alpha = 0.0;
if ([CSToastManager isTapToDismissEnabled]) {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cs_handleToastTapped:)];
[toast addGestureRecognizer:recognizer];
toast.userInteractionEnabled = YES;
toast.exclusiveTouch = YES;
}
[[self cs_activeToasts] addObject:toast];
[self addSubview:toast];
[UIView animateWithDuration:[[CSToastManager sharedStyle] fadeDuration]
delay:0.0
options:(UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction)
animations:^{
toast.alpha = 1.0;
} completion:^(BOOL finished) {
NSTimer *timer = [NSTimer timerWithTimeInterval:duration target:self selector:@selector(cs_toastTimerDidFinish:) userInfo:toast repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
objc_setAssociatedObject(toast, &CSToastTimerKey, timer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}];
}
- (void)cs_hideToast:(UIView *)toast {
[self cs_hideToast:toast fromTap:NO];
}
- (void)cs_hideToast:(UIView *)toast fromTap:(BOOL)fromTap {
NSTimer *timer = (NSTimer *)objc_getAssociatedObject(toast, &CSToastTimerKey);
[timer invalidate];
[UIView animateWithDuration:[[CSToastManager sharedStyle] fadeDuration]
delay:0.0
options:(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState)
animations:^{
toast.alpha = 0.0;
} completion:^(BOOL finished) {
[toast removeFromSuperview];
// remove
[[self cs_activeToasts] removeObject:toast];
// execute the completion block, if necessary
void (^completion)(BOOL didTap) = objc_getAssociatedObject(toast, &CSToastCompletionKey);
if (completion) {
completion(fromTap);
}
if ([self.cs_toastQueue count] > 0) {
// dequeue
UIView *nextToast = [[self cs_toastQueue] firstObject];
[[self cs_toastQueue] removeObjectAtIndex:0];
// present the next toast
NSTimeInterval duration = [objc_getAssociatedObject(nextToast, &CSToastDurationKey) doubleValue];
id position = objc_getAssociatedObject(nextToast, &CSToastPositionKey);
[self cs_showToast:nextToast duration:duration position:position];
}
}];
}
#pragma mark - View Construction
- (UIView *)toastViewForMessage:(NSString *)message title:(NSString *)title image:(UIImage *)image style:(CSToastStyle *)style {
// sanity
if (message == nil && title == nil && image == nil) return nil;
// default to the shared style
if (style == nil) {
style = [CSToastManager sharedStyle];
}
// dynamically build a toast view with any combination of message, title, & image
UILabel *messageLabel = nil;
UILabel *titleLabel = nil;
UIImageView *imageView = nil;
UIView *wrapperView = [[UIView alloc] init];
wrapperView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
wrapperView.layer.cornerRadius = style.cornerRadius;
if (style.displayShadow) {
wrapperView.layer.shadowColor = style.shadowColor.CGColor;
wrapperView.layer.shadowOpacity = style.shadowOpacity;
wrapperView.layer.shadowRadius = style.shadowRadius;
wrapperView.layer.shadowOffset = style.shadowOffset;
}
wrapperView.backgroundColor = style.backgroundColor;
if(image != nil) {
imageView = [[UIImageView alloc] initWithImage:image];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake(style.horizontalPadding, style.verticalPadding, style.imageSize.width, style.imageSize.height);
}
CGRect imageRect = CGRectZero;
if(imageView != nil) {
imageRect.origin.x = style.horizontalPadding;
imageRect.origin.y = style.verticalPadding;
imageRect.size.width = imageView.bounds.size.width;
imageRect.size.height = imageView.bounds.size.height;
}
if (title != nil) {
titleLabel = [[UILabel alloc] init];
titleLabel.numberOfLines = style.titleNumberOfLines;
titleLabel.font = style.titleFont;
titleLabel.textAlignment = style.titleAlignment;
titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
titleLabel.textColor = style.titleColor;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.alpha = 1.0;
titleLabel.text = title;
// size the title label according to the length of the text
CGSize maxSizeTitle = CGSizeMake((self.bounds.size.width * style.maxWidthPercentage) - imageRect.size.width, self.bounds.size.height * style.maxHeightPercentage);
CGSize expectedSizeTitle = [titleLabel sizeThatFits:maxSizeTitle];
// UILabel can return a size larger than the max size when the number of lines is 1
expectedSizeTitle = CGSizeMake(MIN(maxSizeTitle.width, expectedSizeTitle.width), MIN(maxSizeTitle.height, expectedSizeTitle.height));
titleLabel.frame = CGRectMake(0.0, 0.0, expectedSizeTitle.width, expectedSizeTitle.height);
}
if (message != nil) {
messageLabel = [[UILabel alloc] init];
messageLabel.numberOfLines = style.messageNumberOfLines;
messageLabel.font = style.messageFont;
messageLabel.textAlignment = style.messageAlignment;
messageLabel.lineBreakMode = NSLineBreakByTruncatingTail;
messageLabel.textColor = style.messageColor;
messageLabel.backgroundColor = [UIColor clearColor];
messageLabel.alpha = 1.0;
messageLabel.text = message;
CGSize maxSizeMessage = CGSizeMake((self.bounds.size.width * style.maxWidthPercentage) - imageRect.size.width, self.bounds.size.height * style.maxHeightPercentage);
CGSize expectedSizeMessage = [messageLabel sizeThatFits:maxSizeMessage];
// UILabel can return a size larger than the max size when the number of lines is 1
expectedSizeMessage = CGSizeMake(MIN(maxSizeMessage.width, expectedSizeMessage.width), MIN(maxSizeMessage.height, expectedSizeMessage.height));
messageLabel.frame = CGRectMake(0.0, 0.0, expectedSizeMessage.width, expectedSizeMessage.height);
}
CGRect titleRect = CGRectZero;
if(titleLabel != nil) {
titleRect.origin.x = imageRect.origin.x + imageRect.size.width + style.horizontalPadding;
titleRect.origin.y = style.verticalPadding;
titleRect.size.width = titleLabel.bounds.size.width;
titleRect.size.height = titleLabel.bounds.size.height;
}
CGRect messageRect = CGRectZero;
if(messageLabel != nil) {
messageRect.origin.x = imageRect.origin.x + imageRect.size.width + style.horizontalPadding;
messageRect.origin.y = titleRect.origin.y + titleRect.size.height + style.verticalPadding;
messageRect.size.width = messageLabel.bounds.size.width;
messageRect.size.height = messageLabel.bounds.size.height;
}
CGFloat longerWidth = MAX(titleRect.size.width, messageRect.size.width);
CGFloat longerX = MAX(titleRect.origin.x, messageRect.origin.x);
// Wrapper width uses the longerWidth or the image width, whatever is larger. Same logic applies to the wrapper height.
CGFloat wrapperWidth = MAX((imageRect.size.width + (style.horizontalPadding * 2.0)), (longerX + longerWidth + style.horizontalPadding));
CGFloat wrapperHeight = MAX((messageRect.origin.y + messageRect.size.height + style.verticalPadding), (imageRect.size.height + (style.verticalPadding * 2.0)));
wrapperView.frame = CGRectMake(0.0, 0.0, wrapperWidth, wrapperHeight);
if(titleLabel != nil) {
titleLabel.frame = titleRect;
[wrapperView addSubview:titleLabel];
}
if(messageLabel != nil) {
messageLabel.frame = messageRect;
[wrapperView addSubview:messageLabel];
}
if(imageView != nil) {
[wrapperView addSubview:imageView];
}
return wrapperView;
}
#pragma mark - Storage
- (NSMutableArray *)cs_activeToasts {
NSMutableArray *cs_activeToasts = objc_getAssociatedObject(self, &CSToastActiveKey);
if (cs_activeToasts == nil) {
cs_activeToasts = [[NSMutableArray alloc] init];
objc_setAssociatedObject(self, &CSToastActiveKey, cs_activeToasts, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return cs_activeToasts;
}
- (NSMutableArray *)cs_toastQueue {
NSMutableArray *cs_toastQueue = objc_getAssociatedObject(self, &CSToastQueueKey);
if (cs_toastQueue == nil) {
cs_toastQueue = [[NSMutableArray alloc] init];
objc_setAssociatedObject(self, &CSToastQueueKey, cs_toastQueue, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return cs_toastQueue;
}
#pragma mark - Events
- (void)cs_toastTimerDidFinish:(NSTimer *)timer {
[self cs_hideToast:(UIView *)timer.userInfo];
}
- (void)cs_handleToastTapped:(UITapGestureRecognizer *)recognizer {
UIView *toast = recognizer.view;
NSTimer *timer = (NSTimer *)objc_getAssociatedObject(toast, &CSToastTimerKey);
[timer invalidate];
[self cs_hideToast:toast fromTap:YES];
}
#pragma mark - Activity Methods
- (void)makeToastActivity:(id)position {
// sanity
UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey);
if (existingActivityView != nil) return;
CSToastStyle *style = [CSToastManager sharedStyle];
UIView *activityView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, style.activitySize.width, style.activitySize.height)];
activityView.center = [self cs_centerPointForPosition:position withToast:activityView];
activityView.backgroundColor = style.backgroundColor;
activityView.alpha = 0.0;
activityView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);
activityView.layer.cornerRadius = style.cornerRadius;
if (style.displayShadow) {
activityView.layer.shadowColor = style.shadowColor.CGColor;
activityView.layer.shadowOpacity = style.shadowOpacity;
activityView.layer.shadowRadius = style.shadowRadius;
activityView.layer.shadowOffset = style.shadowOffset;
}
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicatorView.center = CGPointMake(activityView.bounds.size.width / 2, activityView.bounds.size.height / 2);
[activityView addSubview:activityIndicatorView];
[activityIndicatorView startAnimating];
// associate the activity view with self
objc_setAssociatedObject (self, &CSToastActivityViewKey, activityView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self addSubview:activityView];
[UIView animateWithDuration:style.fadeDuration
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
activityView.alpha = 1.0;
} completion:nil];
}
- (void)hideToastActivity {
UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey);
if (existingActivityView != nil) {
[UIView animateWithDuration:[[CSToastManager sharedStyle] fadeDuration]
delay:0.0
options:(UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState)
animations:^{
existingActivityView.alpha = 0.0;
} completion:^(BOOL finished) {
[existingActivityView removeFromSuperview];
objc_setAssociatedObject (self, &CSToastActivityViewKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}];
}
}
#pragma mark - Helpers
- (CGPoint)cs_centerPointForPosition:(id)point withToast:(UIView *)toast {
CSToastStyle *style = [CSToastManager sharedStyle];
UIEdgeInsets safeInsets = UIEdgeInsetsZero;
if (@available(iOS 11.0, *)) {
safeInsets = self.safeAreaInsets;
}
CGFloat topPadding = style.verticalPadding + safeInsets.top;
CGFloat bottomPadding = style.verticalPadding + safeInsets.bottom;
if([point isKindOfClass:[NSString class]]) {
if([point caseInsensitiveCompare:CSToastPositionTop] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width / 2.0, (toast.frame.size.height / 2.0) + topPadding);
} else if([point caseInsensitiveCompare:CSToastPositionCenter] == NSOrderedSame) {
return CGPointMake(self.bounds.size.width / 2.0, self.bounds.size.height / 2.0);
}
} else if ([point isKindOfClass:[NSValue class]]) {
return [point CGPointValue];
}
// default to bottom
return CGPointMake(self.bounds.size.width / 2.0, (self.bounds.size.height - (toast.frame.size.height / 2.0)) - bottomPadding);
}
@end
@implementation CSToastStyle
#pragma mark - Constructors
- (instancetype)initWithDefaultStyle {
self = [super init];
if (self) {
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
self.titleColor = [UIColor whiteColor];
self.messageColor = [UIColor whiteColor];
self.maxWidthPercentage = 0.8;
self.maxHeightPercentage = 0.8;
self.horizontalPadding = 10.0;
self.verticalPadding = 10.0;
self.cornerRadius = 10.0;
self.titleFont = [UIFont boldSystemFontOfSize:16.0];
self.messageFont = [UIFont systemFontOfSize:16.0];
self.titleAlignment = NSTextAlignmentLeft;
self.messageAlignment = NSTextAlignmentLeft;
self.titleNumberOfLines = 0;
self.messageNumberOfLines = 0;
self.displayShadow = NO;
self.shadowOpacity = 0.8;
self.shadowRadius = 6.0;
self.shadowOffset = CGSizeMake(4.0, 4.0);
self.imageSize = CGSizeMake(80.0, 80.0);
self.activitySize = CGSizeMake(100.0, 100.0);
self.fadeDuration = 0.2;
}
return self;
}
- (void)setMaxWidthPercentage:(CGFloat)maxWidthPercentage {
_maxWidthPercentage = MAX(MIN(maxWidthPercentage, 1.0), 0.0);
}
- (void)setMaxHeightPercentage:(CGFloat)maxHeightPercentage {
_maxHeightPercentage = MAX(MIN(maxHeightPercentage, 1.0), 0.0);
}
- (instancetype)init NS_UNAVAILABLE {
return nil;
}
@end
@interface CSToastManager ()
@property (strong, nonatomic) CSToastStyle *sharedStyle;
@property (assign, nonatomic, getter=isTapToDismissEnabled) BOOL tapToDismissEnabled;
@property (assign, nonatomic, getter=isQueueEnabled) BOOL queueEnabled;
@property (assign, nonatomic) NSTimeInterval defaultDuration;
@property (strong, nonatomic) id defaultPosition;
@end
@implementation CSToastManager
#pragma mark - Constructors
+ (instancetype)sharedManager {
static CSToastManager *_sharedManager = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
_sharedManager = [[self alloc] init];
});
return _sharedManager;
}
- (instancetype)init {
self = [super init];
if (self) {
self.sharedStyle = [[CSToastStyle alloc] initWithDefaultStyle];
self.tapToDismissEnabled = YES;
self.queueEnabled = NO;
self.defaultDuration = 3.0;
self.defaultPosition = CSToastPositionBottom;
}
return self;
}
#pragma mark - Singleton Methods
+ (void)setSharedStyle:(CSToastStyle *)sharedStyle {
[[self sharedManager] setSharedStyle:sharedStyle];
}
+ (CSToastStyle *)sharedStyle {
return [[self sharedManager] sharedStyle];
}
+ (void)setTapToDismissEnabled:(BOOL)tapToDismissEnabled {
[[self sharedManager] setTapToDismissEnabled:tapToDismissEnabled];
}
+ (BOOL)isTapToDismissEnabled {
return [[self sharedManager] isTapToDismissEnabled];
}
+ (void)setQueueEnabled:(BOOL)queueEnabled {
[[self sharedManager] setQueueEnabled:queueEnabled];
}
+ (BOOL)isQueueEnabled {
return [[self sharedManager] isQueueEnabled];
}
+ (void)setDefaultDuration:(NSTimeInterval)duration {
[[self sharedManager] setDefaultDuration:duration];
}
+ (NSTimeInterval)defaultDuration {
return [[self sharedManager] defaultDuration];
}
+ (void)setDefaultPosition:(id)position {
if ([position isKindOfClass:[NSString class]] || [position isKindOfClass:[NSValue class]]) {
[[self sharedManager] setDefaultPosition:position];
}
}
+ (id)defaultPosition {
return [[self sharedManager] defaultPosition];
}
@end

View File

@ -42,6 +42,14 @@ static NSString * const kClientID =
vc.content = content;
vc.tipTitle = title;
vc.autosave = TRUE;
NSString *tipTxt = @"This QR code is only used to export account recovery private key.\n \
\n \
1. Use CEBG client to scan the QR code to get the account recovery private key. \n\
\n \
2. Account of ios cannot login to Andorid device. \n \
\n \
3. Please keep your private key as safe as possible.";
vc.tipTxt = tipTxt;
[self presentViewController:vc animated:YES completion:nil];
});
}
@ -63,9 +71,8 @@ static NSString * const kClientID =
-(void)scanQRCode:(NSString *)funid title:(NSString *) title{
NSLog(@"scanQRCode:: funId: %@ title: %@", funid, title);
dispatch_async(dispatch_get_main_queue(), ^{
[self openLocalPhotoAlbum];
});
[self openLocalPhotoAlbum];
// std::string sfunid = std::string([funid UTF8String], [funid lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
// if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) {
@ -221,9 +228,9 @@ static NSString * const kClientID =
}
#pragma mark- - PhotoAlbum
- (void)openLocalPhotoAlbum
{
__weak __typeof(self) weakSelf = self;
- (void)openLocalPhotoAlbum {
__weak __typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[LBXPermission authorizeWithType:LBXPermissionType_Photos completion:^(BOOL granted, BOOL firstTime) {
if (granted) {
[weakSelf openLocalPhoto];
@ -233,6 +240,7 @@ static NSString * const kClientID =
[LBXPermissionSetting showAlertToDislayPrivacySettingWithTitle:@"提示" msg:@"没有相册权限,是否前往设置" cancel:@"取消" setting:@"设置"];
}
}];
});
}

View File

@ -79,6 +79,8 @@
D0DD4D8D8AC82F06A4331428 /* libil2cpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 924940699744FB37428516DD /* libil2cpp.a */; };
D52A8DA1288E6547006574E8 /* libuv_a.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D52A8D9F288E6547006574E8 /* libuv_a.a */; };
D5538BA5287E9908000BDFB6 /* WalletEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */; };
D56436422930AAF700E2B633 /* UIView+Toast.m in Sources */ = {isa = PBXBuildFile; fileRef = D56436412930AAF700E2B633 /* UIView+Toast.m */; };
D56436462930ABAB00E2B633 /* UIUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D56436452930ABAB00E2B633 /* UIUtils.m */; };
D579209F292F3C94004DBD4F /* LBXScanNative.m in Sources */ = {isa = PBXBuildFile; fileRef = D579209E292F3C94004DBD4F /* LBXScanNative.m */; };
D57920A2292F3D28004DBD4F /* LBXScanTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = D57920A1292F3D28004DBD4F /* LBXScanTypes.m */; };
D57920A5292F4738004DBD4F /* QrCodeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D57920A4292F4738004DBD4F /* QrCodeViewController.xib */; };
@ -372,6 +374,10 @@
D52A8D9F288E6547006574E8 /* libuv_a.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libuv_a.a; sourceTree = "<group>"; };
D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WalletEvent.cpp; sourceTree = "<group>"; };
D5538BA4287E9908000BDFB6 /* WalletEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WalletEvent.h; sourceTree = "<group>"; };
D56436402930AAF700E2B633 /* UIView+Toast.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIView+Toast.h"; sourceTree = "<group>"; };
D56436412930AAF700E2B633 /* UIView+Toast.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIView+Toast.m"; sourceTree = "<group>"; };
D56436442930ABAB00E2B633 /* UIUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIUtils.h; sourceTree = "<group>"; };
D56436452930ABAB00E2B633 /* UIUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIUtils.m; sourceTree = "<group>"; };
D579209C292F3C94004DBD4F /* LBXScanNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LBXScanNative.h; sourceTree = "<group>"; };
D579209E292F3C94004DBD4F /* LBXScanNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LBXScanNative.m; sourceTree = "<group>"; };
D57920A0292F3D28004DBD4F /* LBXScanTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LBXScanTypes.h; sourceTree = "<group>"; };
@ -968,6 +974,10 @@
D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */,
D57920A3292F45D3004DBD4F /* qr */,
D59AB434292E389E00714392 /* KeyChain */,
D56436402930AAF700E2B633 /* UIView+Toast.h */,
D56436412930AAF700E2B633 /* UIView+Toast.m */,
D56436442930ABAB00E2B633 /* UIUtils.h */,
D56436452930ABAB00E2B633 /* UIUtils.m */,
);
path = Classes_cocos;
sourceTree = "<group>";
@ -1255,6 +1265,7 @@
85E5623820F4F4D1001DFEF6 /* UnityView+Keyboard.mm in Sources */,
D5F2CF98287BEC0D003C2B62 /* Bulk_UnityEngine_0.cpp in Sources */,
D5F2CF64287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_11Table.cpp in Sources */,
D56436462930ABAB00E2B633 /* UIUtils.m in Sources */,
8A3EDDC81615B7C1001839E9 /* SplashScreen.mm in Sources */,
D5538BA5287E9908000BDFB6 /* WalletEvent.cpp in Sources */,
D5F2CFA7287BEC0D003C2B62 /* Bulk_UnityEngine.UI_2.cpp in Sources */,
@ -1363,6 +1374,7 @@
D5F2CFA3287BEC0D003C2B62 /* Bulk_mscorlib_14.cpp in Sources */,
8A25E6D218D767E20006A227 /* Filesystem.mm in Sources */,
D5AB1D3428BF782300AA6AFA /* QRCameraSwitchButton.m in Sources */,
D56436422930AAF700E2B633 /* UIView+Toast.m in Sources */,
D5F2CF74287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_20Table.cpp in Sources */,
D5F2CF9C287BEC0D003C2B62 /* Bulk_mscorlib_16.cpp in Sources */,
999475201A7BC3AE00178130 /* UnityAdsUnityWrapper.mm in Sources */,

View File

@ -14,8 +14,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "11"
endingColumnNumber = "11"
startingLineNumber = "107"
endingLineNumber = "107"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -30,8 +30,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "105"
endingLineNumber = "105"
startingLineNumber = "112"
endingLineNumber = "112"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -46,8 +46,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "107"
endingLineNumber = "107"
startingLineNumber = "114"
endingLineNumber = "114"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -62,8 +62,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "106"
endingLineNumber = "106"
startingLineNumber = "113"
endingLineNumber = "113"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -78,8 +78,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "112"
endingLineNumber = "112"
startingLineNumber = "119"
endingLineNumber = "119"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -110,8 +110,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
startingLineNumber = "73"
endingLineNumber = "73"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -126,8 +126,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "70"
endingLineNumber = "70"
startingLineNumber = "77"
endingLineNumber = "77"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>
@ -142,8 +142,8 @@
filePath = "Classes_cocos/UIViewController+Wallet.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
endingLineNumber = "64"
startingLineNumber = "72"
endingLineNumber = "72"
landmarkName = "-scanQRCode:title:"
landmarkType = "7">
</BreakpointContent>

View File

@ -165,8 +165,8 @@ function createAccount(funId) {
*/
function importAccount(funId, privateKey) {
console.log('importAccount: ' + funId);
// jsb.scanQRCode(funId, '111');
jsb.showQRCode('00123', '0x12312312313123123123', 'CEBG RECOVERY KEY', '0x1231231231321231');
jsb.scanQRCode(funId, '111');
// jsb.showQRCode('00123', '0x12312312313123123123', 'CEBG RECOVERY KEY', '0x1231231231321231');
// try {
// let address = jc.wallet.importAccount(privateKey);
// return JSON.stringify({