每个客户端的 IOS 目标 [英] IOS Targets for each client

查看:37
本文介绍了每个客户端的 IOS 目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一点背景:

在android中我们开发了相同的应用程序,基本上我们首先开发了Android应用程序,现在我们已经创建了它的IOS版本,所以这个应用程序有多个客户端.在 android 中,我们确实使用 Android 模块系统来处理这种情况.

In android we have developed the same app, basically we have developed the Android app first now we have created its IOS version, so there are multiple clients of this app. In android we are really handling this situation using Android modules system.

现在在 IOS 中我们必须做同样的事情.那就是使相同的代码库可用于多个客户端.

Now in IOS we have to do same thing. And that is to make the samecode base to be use in for multiple clients.

我做了研究,发现目标和框架是最好的选择.我创建了工作区,添加了框架并添加了项目.但这一切都无缘无故地陷入困境.

I did research and found the Targets and framework are the best option. I created the workspace added the framework and added the projects. But it all going in trouble for no reason.

所以我决定转向目标.所以我读了,它很容易理解,但能不能满足我的以下要求

So I decided to move onto targets. So I read and its easy to understand but can it satisfy my following requirements

  1. 为每个目标创建单独的 swift 文件.(我有一个包含 URL 链接和其他内容的通用文件,每个客户端都需要不同的文件,所以我可以为每个客户端制作相同的文件,并更改 url 和其他内容
  2. 应用图标(每个目标必须有单独的图标)
  3. 关闭应用程序的颜色(我想为每个客户端使用不同的颜色.在这里我真的不知道该怎么做,因为我已经使用 IB 为应用程序提供了颜色)
  4. FCM 及其文件GoogleService-Info.plist"(如何为多个目标管理)

更新:这就是我在 App Delegate 中编码的方式

Update: This is How I am coding in App Delegate

    import Firebase
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    let gcmMessageIDKey = "gcm.message_id"

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        FirebaseApp.configure()

        // [START set_messaging_delegate]
        Messaging.messaging().delegate = self
        // [END set_messaging_delegate]
        // Register for remote notifications. This shows a permission dialog on first run, to
        // show the dialog at a more appropriate time move this registration accordingly.
        // [START register_for_notifications]
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self

            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings =
                UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()

        // [END register_for_notifications]
        return true
    }

    // [START receive_message]
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification
        // With swizzling disabled you must let Messaging know about the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }

        // Print full message.
        print(userInfo)
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification
        // With swizzling disabled you must let Messaging know about the message, for Analytics
        // Messaging.messaging().appDidReceiveMessage(userInfo)
        // Print message ID.
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }

        // Print full message.
        print(userInfo)

        completionHandler(UIBackgroundFetchResult.newData)
    }

请告诉使用目标"是否可以实现?如何实现?

Please tell is it achievable using "Targets" and how?

推荐答案

1. 当您创建目标时,在此之前添加的所有文件都将可用于新创建的目标.然后对于您添加的每个新文件,您可以选择该文件的目标.您可以在文件检查器的目标成员资格部分更改该首选项.

1. When you create target all files added till then will be available to the newly created target. Then for every new file you add you can choose the target for that file. You can change that preference in target membership section in file inspector.

2.您可以为不同的目标设置不同的应用图标

2. You can have different app icon for different targets

  1. 在 Assets 中创建不同的应用图标
  2. 然后在目标 -> 应用图标部分设置新创建的应用图标.

  1. Create a different app icon in Assets
  2. Then set the newly created app icon in target -> App icon section.

3.对于不同的颜色:

您可以为每个目标设置编译标志

You can set compile flags for each target

在 Swift Compiler — Custom Flags → Other Swift Flags 下的目标构建设置中找到 Swift 编译器标志

Locate Swift compiler flags in the target build settings under Swift Compiler — Custom Flags → Other Swift Flags

在其他 swift 标志中创建的标志将有助于区分目标.然后根据值给出这样的颜色

Created flag in other swift flags will help to distinguish between the target. Then Depending upon the value give color like this

#if TARGET1

let fillColor       = UIColor(red: 30/255.0, green: 100/255.0, blue: 100/255.0, alpha: 1.0)
let fillColorWithAlpha  = UIColor(red: 30/255.0, green: 100/255.0, blue: 100/255.0, alpha: 0.9)

let buttonColor     = UIColor(red: 15/255.0, green: 45/255.0, blue: 90/255.0, alpha: 1.0)
let buttonColorDeselected = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 1.0)



#else
let fillColor       = UIColor(red: 74/255.0, green: 144/255.0, blue: 226/255.0, alpha: 1.0)
let fillColorWithAlpha       = UIColor(red: 74/255.0, green: 144/255.0, blue: 226/255.0, alpha: 0.9)

let buttonColor     = UIColor(red: 36/255.0, green: 97/255.0, blue: 168/255.0, alpha: 1.0)
let buttonColorDeselected = UIColor(red: 116/255, green: 116/255, blue: 116/255, alpha: 1.0)



#endif 

其中TARGET1"是您在 swift 标志部分给出的值.

Where "TARGET1" is the value you have given in swift flag section.

最后使用您配置的此填充颜色来更改颜色.例如,将 UIButton 的背景颜色设置为该颜色 -> 创建自定义类并提供您为不同目标配置的颜色.通过这样做,您只需更改配置中的颜色,而无需更新整个 UI

Lastly Use this fillColor that you configured to change the Color. For Example to set background color of UIButton to that color -> Create custom class and give the color that you have configured for different target. By doing this you can just change the color in configuration rather than updating the entire UI

class CustomThemeButton: UIButton {


    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setBackGroundColor()
    }

    required override init(frame: CGRect) {
        super.init(frame: frame)
        setBackGroundColor()
    }

    private func setBackGroundColor(){

        self.backgroundColor = fillColor
    }

}

这篇关于每个客户端的 IOS 目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆