Mac Catalyst iPad App移植 筆記

0、

最簡(jiǎn)單的一步:


勾選Mac

官方教程

Xcode相關(guān)

注意3び弧4沓馈!這個(gè)Architectures要加一個(gè)
Architectures -> valid architecture
添加一個(gè) x86_64


添加一個(gè) x86_64.png

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增热、

Undefined symbol: _OBJC_CLASS_$_XXXXXXX.png

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配置

可能遇到的問題:

  1. 與iOS不同人断,所有在mac上運(yùn)行的bundle都需要簽名(sign)。
    解決步驟:點(diǎn)擊 Pod Target 里 "Signing & Capabilities"中選擇一個(gè)Team
bundle需要簽名

上傳商店遇到這個(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

一個(gè)大而全的教程

打包問題:
1恶迈、archive 刪掉Siri 功能(有的話)
2、蘋果后臺(tái)證書谱醇、appid暇仲、描述文件都不用動(dòng),簽名選擇自動(dòng)(對(duì)外發(fā)布需要公證)
macOS應(yīng)用Notarization公證機(jī)制

關(guān)于上架

在iOS提交界面選擇macOS版本,按之前iOS的提交步驟提交即可

截屏2020-04-28下午8.38.07.png

上一張運(yùn)行圖

截屏2019-11-01下午6.53.58.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末副渴,一起剝皮案震驚了整個(gè)濱河市奈附,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌煮剧,老刑警劉巖斥滤,帶你破解...
    沈念sama閱讀 218,546評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異勉盅,居然都是意外死亡佑颇,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門草娜,熙熙樓的掌柜王于貴愁眉苦臉地迎上來挑胸,“玉大人,你說我怎么就攤上這事驱还∈缺” “怎么了凸克?”我有些...
    開封第一講書人閱讀 164,911評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵议蟆,是天一觀的道長。 經(jīng)常有香客問我萎战,道長咐容,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評(píng)論 1 294
  • 正文 為了忘掉前任蚂维,我火速辦了婚禮戳粒,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘虫啥。我一直安慰自己蔚约,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評(píng)論 6 392
  • 文/花漫 我一把揭開白布涂籽。 她就那樣靜靜地躺著苹祟,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上树枫,一...
    開封第一講書人閱讀 51,598評(píng)論 1 305
  • 那天直焙,我揣著相機(jī)與錄音,去河邊找鬼砂轻。 笑死奔誓,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的搔涝。 我是一名探鬼主播厨喂,決...
    沈念sama閱讀 40,338評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼庄呈!你這毒婦竟也來了杯聚?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,249評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤抒痒,失蹤者是張志新(化名)和其女友劉穎幌绍,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體故响,經(jīng)...
    沈念sama閱讀 45,696評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡傀广,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了彩届。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片伪冰。...
    茶點(diǎn)故事閱讀 40,013評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖樟蠕,靈堂內(nèi)的尸體忽然破棺而出贮聂,到底是詐尸還是另有隱情,我是刑警寧澤寨辩,帶...
    沈念sama閱讀 35,731評(píng)論 5 346
  • 正文 年R本政府宣布吓懈,位于F島的核電站,受9級(jí)特大地震影響靡狞,放射性物質(zhì)發(fā)生泄漏耻警。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評(píng)論 3 330
  • 文/蒙蒙 一甸怕、第九天 我趴在偏房一處隱蔽的房頂上張望甘穿。 院中可真熱鬧,春花似錦梢杭、人聲如沸温兼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽募判。三九已至缸榛,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間兰伤,已是汗流浹背内颗。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評(píng)論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留敦腔,地道東北人均澳。 一個(gè)月前我還...
    沈念sama閱讀 48,203評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像符衔,于是被迫代替她去往敵國和親找前。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容