0、
最簡(jiǎn)單的一步:
注意3び弧4沓馈!這個(gè)Architectures要加一個(gè)
Architectures -> valid architecture
添加一個(gè) x86_64
1疮跑、更改platform
However, you may need to manually exclude other content. To do this, go to the Frameworks, Libraries, and Embedded Content list under the General tab for your iOS target. Then select iOS as the platform setting for the item. This setting excludes the item from the Mac version of your app.
Extention 需要舍棄
2、使用系統(tǒng)提供的宏來處理不兼容的代碼
if frameworks or API that are unavailable to the Mac version of your app. To remedy this problem, find the code that doesn’t compile, and enclose it as shown here:
注意凸舵,這個(gè)宏很重要祖娘,macOS不兼容代碼都可以擱這里邊
#if !TARGET_OS_MACCATALYST
// Code to exclude from Mac.
#endif
另外,也可以這么干啊奄,macOS代碼可以擱這里邊(與上邊相比去掉了 渐苏! )
#if TARGET_OS_MACCATALYST
// Code to exclude from iOS .
#endif
3、一些無法編譯的第三方
Showing All Errors Only
In /Users/XXXXXX/IJKMediaFramework.framework/IJKMediaFramework(IJKMediaPlayback.o), building for Mac Catalyst, but linking in object file built for iOS Simulator, for architecture x86_64
解決方法:
找到這個(gè)IJKMediaFramework在項(xiàng)目中引用的地方,
#if !TARGET_OS_MACCATALYST
目標(biāo)framework
#endif
之后需要解決報(bào)錯(cuò)信息,方法同上
4增热、
Showing All Errors Only
Undefined symbol: OBJC_CLASS$_ALBBSDK
解決方法同3(全局搜索 "ALBBSDK",屏蔽處理)
5整以、
LSSupportsOpeningDocumentsInPlace = NO' is not supported on macOS. Either remove the entry or set it to YES, and also ensure that the application does open documents in place on macOS.
解決方案:新建target
[XCode使用四:XCode工程中創(chuàng)建多個(gè)Targets]https://blog.csdn.net/hitfyb/article/details/50875657
19.10.22 程序編譯成功!峻仇!
上邊這些應(yīng)該是都能遇到的問題公黑,之后仍然有許多問題需要解決,大家加油。
如果使用了 pod
建議新建target凡蚜,pod配置文件根據(jù)target配置
可能遇到的問題:
- 與iOS不同人断,所有在mac上運(yùn)行的bundle都需要簽名(sign)。
解決步驟:點(diǎn)擊 Pod Target 里 "Signing & Capabilities"中選擇一個(gè)Team
上傳商店遇到這個(gè)問題
ITMS-90284: Invalid Code Signing- The executable 'XXX.app/Contents/Frameworks/XXX.framework/Versions/A/Resources/XX.bundle' must be signed with the certificate that is contained in the provisioning profile.
需要在Bundle的Sign界面下的Signing Certificate中選取Sign to Run Locally朝蜘。
以上解決方法參考Mac Catalyst 初步體驗(yàn)+排坑
2.pod中的三方使用 UIWebview等mac catalyst不支持的api,移除掉或者屏蔽掉,或者干脆不引用(pod配置文件中配置),注意, 執(zhí)行pod install之后1中的配置修改會(huì)被抹掉 ,需要重新配置
關(guān)于優(yōu)化
更像macOS App
Optimizing Your iPad App for Mac
Mac catalyst 支持的UIKit 庫列表
官方教程,可以下載Demo做一下參考
UIKit Catalog: Creating and Customizing Views and Controls
添加狀態(tài)欄菜單 以及 快捷鍵
Adding Menus and Shortcuts to the Menu Bar and User Interface.
示例代碼(OC),官方給的Demo使用Swift,請(qǐng)自行查閱
在 AppDelegate中重寫這個(gè)方法: buildMenuWithBuilder
-(void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder{
//插入已存在menu下
//無快捷鍵
UICommand * fileMenuCommend = [UICommand commandWithTitle:@"繼續(xù)皮" image:nil action:@selector(jixuOpenAction) propertyList:nil];
//有快捷鍵
UIKeyCommand * openMenuCommend = [UIKeyCommand commandWithTitle:@"皮一下" image:nil action:@selector(openAction) input:@"O" modifierFlags:UIKeyModifierCommand propertyList:nil];//注意兩個(gè)action不能一樣
UIMenu * openMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.example.apple-samplecode.menus.openMenu" options:UIMenuOptionsDisplayInline children:@[openMenuCommend,fileMenuCommend]];
[builder insertChildMenu:openMenu atStartOfMenuForIdentifier:UIMenuFile];
//添加新的menu
UICommand * cityCommend = [UICommand commandWithTitle:@"青島" image:nil action:@selector(openActionP) propertyList:@"青島"];
UIKeyCommand * cityMenuCommend = [UIKeyCommand commandWithTitle:@"濟(jì)南" image:nil action:@selector(openActionD) input:@"P" modifierFlags:UIKeyModifierCommand propertyList:@"濟(jì)南"];
UIMenu * cityMenu = [UIMenu menuWithTitle:@"城市" image:nil identifier:@"com.example.apple-samplecode.menus.cityMenu" options:@[] children:@[cityCommend,cityMenuCommend]];
[builder insertSiblingMenu:cityMenu afterMenuForIdentifier:UIMenuFile];//添加到文件菜單之后
}
-(void)openAction{
NSLog(@"openAction");
}
-(void) jixuOpenAction{
NSLog(@"openAction");
}
在視圖中檢測(cè)鼠標(biāo)的指針(位置)
使用UIHoverGestureRecognizer
To detect when the user moves the pointer over a view in your app, add a
UIHoverGestureRecognizer to that view.
//創(chuàng)建一個(gè)手勢(shì),并添加到view上
let hover = UIHoverGestureRecognizer(target: self, action: #selector(hovering(_:)))
button.addGestureRecognizer(hover)
//手勢(shì)觸發(fā)的方法
@objc
func hovering(_ recognizer: UIHoverGestureRecognizer) {
switch recognizer.state {
case .began, .changed:
button.titleLabel?.textColor = #colorLiteral(red: 1, green: 0, blue: 0, alpha: 1)
case .ended:
button.titleLabel?.textColor = UIColor.link
default:
break
}
}
//OC代碼
UIHoverGestureRecognizer * hover = [[UIHoverGestureRecognizer alloc]initWithTarget:self action:@selector(hoveringWithRecognizer:)];
[View addGestureRecognizer:hover];
-(void)hoveringWithRecognizer:(UIHoverGestureRecognizer *)recognizer{
switch (recognizer.state) {
case (UIGestureRecognizerStateBegan):
NSLog(@"----------------------------鼠標(biāo)進(jìn)入?yún)^(qū)域");
break;
case (UIGestureRecognizerStateEnded):
NSLog(@"----------------------------鼠標(biāo)離開區(qū)域");
break;
default:
break;
}
}
干掉頂欄
///////也可以參考下邊的方法
https://fleetingpixels.com/blog/2019/6/7/customising-nstoolbar-in-uikit-for-mac-marzipancatalyst
項(xiàng)目不包含 SceneDelegate.h/SceneDelegate.m的 (老項(xiàng)目不帶這倆文件)
appDelegate.m 中
#import <Foundation/Foundation.h>
#import <UIKit/NSToolbar+UIKitAdditions.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window.windowScene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden;//隱藏頂欄
}
項(xiàng)目中包含 SceneDelegate.h/SceneDelegate.m 的(xcode11創(chuàng)建默認(rèn)創(chuàng)建的)
在SceneDelegate.m
#import <Foundation/Foundation.h>
#import <UIKit/NSToolbar+UIKitAdditions.h>
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene * windowScene = scene;
windowScene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden;
}
demo:
https://github.com/davidcaddy/UIKitForMacTestTabBarApp
----效果
頂欄添加工具欄(NSToolbar)
在appdelegate的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中添加代碼
//macOS隱藏頂欄
self.window.windowScene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden;
NSToolbar * toolbar = [[NSToolbar alloc]initWithIdentifier:@"ITTitleToolbar"];
toolbar.delegate = self;
toolbar.centeredItemIdentifier = @"居中的ItemIdentifier";//例如ITtabbar
self.window.windowScene.titlebar.toolbar = toolbar;
appdelegate遵循下協(xié)議 : NSToolbarDelegate
在.m中實(shí)現(xiàn)協(xié)議
#pragma mark - NSToolbarDelegate
//所有的item 標(biāo)識(shí)
-(NSArray<NSToolbarItemIdentifier> *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar{
return @[@"addButton",@"ITtabbar",NSToolbarFlexibleSpaceItemIdentifier,@"searchBar"];
}
-(NSArray<NSToolbarItemIdentifier> *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar{
return @[@"addButton",@"ITtabbar",NSToolbarFlexibleSpaceItemIdentifier,@"searchBar"];
}
//選中變灰
//-(NSArray<NSToolbarItemIdentifier> *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar{
// return @[@"addButton",@"ITtabbar",@"searchBar"];
//}
//根據(jù)item 標(biāo)識(shí) 返回每個(gè)具體的NSToolbarItem對(duì)象實(shí)例
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
if ([itemIdentifier isEqualToString:@"ITtabbar"]) {
//這里要用NSToolbarItemGroup,子項(xiàng)不會(huì)分開,居中設(shè)置也可以是它(ITtabbar)
NSToolbarItemGroup * group = [NSToolbarItemGroup groupWithItemIdentifier:@"ITtabbar" titles:@[@"資訊",@"辣品",@"圈子",@"我"] selectionMode:NSToolbarItemGroupSelectionModeSelectOne labels:@[@"section1", @"section2",@"section3", @"section4"] target:self action:@selector(toolbarItemClicked:)];
[group setSelectedIndex:0];
return group;
}
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
if ([itemIdentifier isEqualToString:@"addButton"]) {
[toolbarItem setToolTip:@"更多"];
[toolbarItem setImage:[UIImage imageNamed:@"SmallAttentionButton"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(addToolbarItemClicked:)];
toolbarItem.bordered = YES;
}
else if ([itemIdentifier isEqualToString:@"searchBar"]) {
[toolbarItem setToolTip:@"搜索"];
[toolbarItem setImage:[UIImage imageNamed:@"short_search"]];
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(searchToolbarItemClicked:)];
toolbarItem.bordered = YES;
}
else {
toolbarItem = nil;
}
return toolbarItem;
}
- (void)toolbarItemClicked:(NSToolbarItemGroup *)toolbarItemGroup{
switch (toolbarItemGroup.selectedIndex) {
case 0:
NSLog(@"點(diǎn)擊的是資訊");
break;
case 1:
NSLog(@"點(diǎn)擊的是辣品");
break;
case 2:
NSLog(@"點(diǎn)擊的是圈子");
break;
case 3:
NSLog(@"點(diǎn)擊的是我");
break;
default:
break;
}
}
- (void)searchToolbarItemClicked:(NSToolbarItem *)toolbarItem{
NSLog(@"點(diǎn)擊的是%@",toolbarItem.toolTip);
}
- (void)addToolbarItemClicked:(NSToolbarItem *)toolbarItem{
NSLog(@"點(diǎn)擊的是%@",toolbarItem.toolTip);
}
NSToolbarFlexibleSpaceItemIdentifier的解釋
用這個(gè)可以達(dá)到居右對(duì)齊效果
示例代碼現(xiàn)在是左中右布局,要在中間的item之后加入這個(gè),不然右邊的item會(huì)緊挨著中間的這個(gè)item
參考!!!!!可解決一些問題,獲得啟發(fā)
https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit
打包問題:
1恶迈、archive 刪掉Siri 功能(有的話)
2、蘋果后臺(tái)證書谱醇、appid暇仲、描述文件都不用動(dòng),簽名選擇自動(dòng)(對(duì)外發(fā)布需要公證)
macOS應(yīng)用Notarization公證機(jī)制
關(guān)于上架
在iOS提交界面選擇macOS版本,按之前iOS的提交步驟提交即可
上一張運(yùn)行圖