gpt4 book ai didi

每个客户端的 IOS 目标

转载 作者:行者123 更新时间:2023-11-29 11:33:17 30 4
gpt4 key购买 nike

一些背景知识:

在android中我们开发了同样的应用,基本上我们先开发了Android应用,现在我们创建了它的IOS版本,所以这个应用有多个客户端。在 android 中,我们实际上是使用 Android 模块系统来处理这种情况。

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

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

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

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

更新:这就是我在 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)
}

请说明使用“目标”是否可以实现以及如何实现?

最佳答案

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

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

  1. 在 Assets 中创建不同的应用程序图标
  2. 然后在 target -> App icon 部分设置新创建的应用程序图标。

    enter image description here

    enter image description here

3.对于不同的颜色:

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

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

enter image description here

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

#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 标志部分中提供的值。

最后使用您配置的 fillColor 来更改颜色。例如,将 UIButton 的背景颜色设置为该颜色 -> 创建自定义类并提供您为不同目标配置的颜色。通过这样做,您可以只更改配置中的颜色,而不是更新整个 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 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51491520/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com