1、按钮的点击事件
(1)在Main.storyboard文件放一个button,右键Referencing Outlets 按住拉到ViewControler.m文件的接口中间
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *main_btn;//自动生成的
@end
- (void)viewDidLoad {
[super viewDidLoad];
[_main_btn addTarget:self action:@selector(abc:) forControlEvents:UIControlEventTouchUpInside];
}
- (IBAction)abc:(id)sender {
//点击内容
}
2、修改app图标
在项目里面点击Assets.xcassets的AppIcon 可以修改图标
3、动态修改状态字体颜色
(1)在Info.plist里面添加 View controller-based status bar appearance Boolean NO
在ViewController里面任何地方配置都可以
[UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleLightContent; //状态栏白字
[UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleDefault;//状态栏黑字
4、IOSWkWebView加载网页,跨域问题,js交互
(1)在ViewController.h添加webview组件
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
@interface ViewController : UIViewController
{
WKWebView *webView;
}
@end
(2)在ViewController.m初始化webview组件
#import <WebKit/WebKit.h>
- (void)viewDidLoad {
[super viewDidLoad];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
[configuration setValue:@YES forKey:@"_allowUniversalAccessFromFileURLs"];
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height - 20; //2个20是由于要设配iphone版本 phoneX以上是44以下是20(好像,反正页面太高或太低就改这2个值,一定要一样)
webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 20, width, height) configuration:configuration];
[self setAutomaticallyAdjustsScrollViewInsets:NO];
webView.navigationDelegate = self;
[self.view addSubview: webView];
NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];
[webView loadRequest:request];
[[webView configuration].userContentController addScriptMessageHandler:self name:@"setBlackStateBar"];
[[webView configuration].userContentController addScriptMessageHandler:self name:@"setWhiteStateBar"];
[[webView configuration].userContentController addScriptMessageHandler:self name:@"share"];
}
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
//有参数的时候的取值方法
// NSMutableDictionary *params = [NSMutableDictionary dictionary];
// NSString *title = [dic objectForKey:@"title"];
// NSString *content = [dic objectForKey:@"content"];
// NSString *url = [dic objectForKey:@"url"];
// NSString *imgUrl = [dic objectForKey:@"imgUrl"];
if ([message.name isEqualToString:@"setBlackStateBar"]) {
[UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleDefault; //状态栏字体变黑色
}else if([message.name isEqualToString:@"setWhiteStateBar"]){
[UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleLightContent;//状态栏字体变白色
}else if([message.name isEqualToString:@"share"]){
//动作
}
}
JS调用
//无参数
window.webkit.messageHandlers.setWhiteStateBar.postMessage({});
//有参数
window.webkit.messageHandlers.share.postMessage({title:'标题',content:'测试分享的内容',url:'https://github.com/maying1992',imgUrl:'https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3972947389,1417766871&fm=173&app=49&f=JPEG?w=500&h=306&s=5A024D88F2ED1EAEA2AD0DD7030050A2'})
保存UIImage并在图片列表中可以看到
func loadImage(image:UIImage){
UIImageWriteToSavedPhotosAlbum(image, self, #selector(self.image(image:didFinishSavingWithError:contextInfo:)), nil)
}
//回调
@objc func image(image: UIImage, didFinishSavingWithError: NSError?,contextInfo: AnyObject)
{
if didFinishSavingWithError != nil
{
print("error!")
return
}
}
Xcode 提示报错:Build operations are disabled: ‘Runner.xcworkspace’ has changed and is reloading.
重启Xcode
flutter ios 卡死在闪屏页:
flutter doctor
flutter clean
flutter build ios --release
libc++abi.dylib: terminating with uncaught exception of type NSException
SDK出现libc++abi.dylib: terminating with uncaught exception of type NSException 的问题: 解决方法
结合
监测bug(上线前需要处理掉)
pod 'AvoidCrash' pod 'Bugly'
快速定位问题页面
步骤1:工程文件中选择Build Setting,在"Other Linker Flags"中加入"-ObjC" ,问题就解决了,注意大小写
步骤2:使用字面量字典,如果元素中有nil值时,程序会崩溃,报异常。
xcode重复导包报错
Unexpected duplicate tasks:
-
Target 'image_pickers' (project 'Pods') has copy command from '/Users/dashanwangluo/Desktop/project/flutter/.pub-cache/hosted/pub.flutter-io.cn/image_pickers-1.0.7+3/ios/Classes/AKGallery/img/left_arrow.png' to '/Users/dashanwangluo/Library/Developer/Xcode/DerivedData/Runner-atzrkdnxehanrwgkqwyqhlvkrydh/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/image_pickers.framework/left_arrow.png'
解决方法:
File->WorkSpace Setting
设置软件盘中文
Localization native development region 的值改成 China