分享

macOS Catalyst iPad App移植 笔记

 wintelsui 2020-03-27

注意!!!这个Architectures要加一个
Architectures -> valid architecture
添加一个 x86_64


添加一个 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、使用系统提供的宏来处理不兼容的代码

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:

注意,这个宏很重要,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

解决方法:

找到这个IJKMediaFramework在项目中引用的地方,

#if !TARGET_OS_MACCATALYST

目标framework

#endif

之后需要解决报错信息,方法同上

4、

Undefined symbol: _OBJC_CLASS_$_XXXXXXX.png

Showing All Errors Only

Undefined symbol: OBJC_CLASS$_ALBBSDK

解决方法同3


19.10.22 程序编译成功!!

上边这些应该是都能遇到的问题,之后仍然有许多问题需要解决,大家加油。

关于优化

更像macOS App

Optimizing Your iPad App for Mac
添加状态栏菜单 以及 快捷键
Adding Menus and Shortcuts to the Menu Bar and User Interface.
示例代码(OC),官方给的Demo使用Swift,请自行查阅
在 AppDelegate中重写这个方法: buildMenuWithBuilder

-(void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder{
    //插入已存在menu下
    //无快捷键
    UICommand * fileMenuCommend = [UICommand commandWithTitle:@"继续皮" image:nil action:@selector(jixuOpenAction) propertyList:nil];
    //有快捷键
    UIKeyCommand * openMenuCommend = [UIKeyCommand commandWithTitle:@"皮一下" image:nil action:@selector(openAction) input:@"O" modifierFlags:UIKeyModifierCommand propertyList:nil];//注意两个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:@"济南" image:nil action:@selector(openActionD) input:@"P" modifierFlags:UIKeyModifierCommand propertyList:@"济南"];
    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");
}

在视图中检测鼠标的指针(位置)
使用UIHoverGestureRecognizer
To detect when the user moves the pointer over a view in your app, add a
UIHoverGestureRecognizer to that view.

//创建一个手势,并添加到view上
let hover = UIHoverGestureRecognizer(target: self, action: #selector(hovering(_:)))
button.addGestureRecognizer(hover)
//手势触发的方法
 @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
        }
    }

干掉頂栏
https:///blog/2019/6/7/customising-nstoolbar-in-uikit-for-mac-marzipancatalyst

项目不包含 SceneDelegate.h/SceneDelegate.m的 (老项目不带这俩文件)
appDelegate.m 中

#import <Foundation/Foundation.h>
#import <UIKit/NSToolbar+UIKitAdditions.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
            self.window.windowScene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden;//隐藏顶栏
}

项目中包含 SceneDelegate.h/SceneDelegate.m 的(xcode11创建默认创建的)
在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
----效果

去掉顶栏

参考!!!!!可解决一些问题,获得启发
https://www./blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit

打包问题:
1、archive 删掉Siri 功能(有的话)
2、苹果后台证书、appid、描述文件都不用动,签名选择自动(对外发布需要公证)
macOS应用Notarization公证机制
上一张运行图

截屏2019-11-01下午6.53.58.png

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多