【发布时间】:2018-07-24 06:06:23
【问题描述】:
一点背景:
在android中我们开发了同样的应用程序,基本上我们是先开发了Android应用程序,现在我们已经创建了它的IOS版本,所以这个应用程序有多个客户端。在 android 中,我们确实使用 Android 模块系统来处理这种情况。
现在在 IOS 中我们必须做同样的事情。那就是使相同的代码库用于多个客户端。
我做了研究,发现目标和框架是最好的选择。我创建了工作区,添加了框架并添加了项目。但这一切都无缘无故地陷入困境。
所以我决定转向目标。所以我读了它,它很容易理解,但它可以满足我的以下要求
- 为每个目标单独的 swift 文件。 (我有一个包含 URL 链接和其他内容的通用文件,每个客户端需要的内容不同,所以我可以为每个客户端制作相同的文件并更改 url 和其他内容
- 应用图标(每个目标必须有单独的图标)
- 颜色关闭应用程序(我想为每个客户提供不同的颜色。这里我真的不知道该怎么做,因为我已经使用 IB 给应用程序颜色)
- 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)
}
请说明使用“目标”是否可以实现以及如何实现?
【问题讨论】:
-
它是
iOS而不是IOS。 IOS 是 Cisco 使用的术语。是的,目标是做到这一点的正确方法。 -
@adev 谢谢,下次我会小心的