Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .yamato/upm-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test_editors:
- version: trunk
- version: 6000.6
- version: 6000.5
- version: 6000.4
- version: 6000.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
if (buildTarget != BuildTarget.iOS)
return;

// Check if we have the minimal iOS version set.
bool hasMinOSVersion;
try
{
var requiredVersion = new Version(10, 0);
var currentVersion = new Version(PlayerSettings.iOS.targetOSVersionString);
hasMinOSVersion = currentVersion >= requiredVersion;
}
catch (Exception)
{
hasMinOSVersion = false;
}

if (!hasMinOSVersion)
Debug.Log("UserNotifications framework is only available on iOS 10.0+, please make sure that you set a correct `Target minimum iOS Version` in Player Settings.");

var settings = NotificationSettingsManager.Initialize().iOSNotificationSettingsFlat;

var needLocationFramework = (bool)settings.Find(i => i.Key == NotificationSettings.iOSSettings.USE_LOCATION_TRIGGER).Value;
Expand All @@ -55,8 +39,10 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
private static void PatchPBXProject(string path, bool needLocationFramework, bool addPushNotificationCapability, bool useReleaseAPSEnv, bool addTimeSensitiveEntitlement)
{
var pbxProjectPath = PBXProject.GetPBXProjectPath(path);
List<string> swiftPropertiesToAdd = new();

var needsToWriteChanges = false;
var needsCodeSignEntitlements = false;

var pbxProject = new PBXProject();
pbxProject.ReadFromString(File.ReadAllText(pbxProjectPath));
Expand Down Expand Up @@ -87,25 +73,30 @@ private static void PatchPBXProject(string path, bool needLocationFramework, boo
if (needLocationFramework && !pbxProject.ContainsFramework(unityFrameworkTarget, "CoreLocation.framework"))
{
pbxProject.AddFrameworkToProject(unityFrameworkTarget, "CoreLocation.framework", false);
swiftPropertiesToAdd.Add("-DUNITY_USES_LOCATION");
needsToWriteChanges = true;
}

if (needsToWriteChanges)
File.WriteAllText(pbxProjectPath, pbxProject.WriteToString());

var entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS");
if (entitlementsFileName == null)
string entitlementsFileName = null;
if (addPushNotificationCapability || addTimeSensitiveEntitlement)
{
var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
entitlementsFileName = string.Format("{0}.entitlements", bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1));
entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS");
if (entitlementsFileName == null)
{
var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
entitlementsFileName = string.Format("{0}.entitlements", bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1));
needsCodeSignEntitlements = true;
}
}

// Update the entitlements file.
if (addPushNotificationCapability)
{
swiftPropertiesToAdd.Add("-DUNITY_USES_REMOTE_NOTIFICATIONS");
var capManager = new ProjectCapabilityManager(pbxProjectPath, entitlementsFileName, "Unity-iPhone");
capManager.AddPushNotifications(!useReleaseAPSEnv);
capManager.WriteToFile();
needsToWriteChanges = true;
}

if (addTimeSensitiveEntitlement)
Expand All @@ -120,12 +111,22 @@ private static void PatchPBXProject(string path, bool needLocationFramework, boo
entitlementsFile.root["com.apple.developer.usernotifications.time-sensitive"] = new PlistElementBoolean(true);
entitlementsFile.WriteToFile(entitlementsFilePath);
}
if (pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS") == null)
{
pbxProject.AddBuildProperty(mainTarget, "CODE_SIGN_ENTITLEMENTS", entitlementsFileName);
pbxProject.WriteToFile(pbxProjectPath);
}
}

if (needsCodeSignEntitlements)
{
pbxProject.AddBuildProperty(mainTarget, "CODE_SIGN_ENTITLEMENTS", entitlementsFileName);
needsToWriteChanges = true;
}

if (swiftPropertiesToAdd.Count > 0)
{
pbxProject.UpdateBuildProperty(unityFrameworkTarget, "OTHER_SWIFT_FLAGS", swiftPropertiesToAdd, new string[0]);
needsToWriteChanges = true;
}

if (needsToWriteChanges)
Comment thread
aurimasc marked this conversation as resolved.
pbxProject.WriteToFile(pbxProjectPath);
}

private static void PatchPlist(string path, List<Unity.Notifications.NotificationSetting> settings, bool addPushNotificationCapability)
Expand Down Expand Up @@ -193,7 +194,12 @@ private static void PatchPreprocessor(string path, bool needLocationFramework, b
if (!(needLocationFramework || addPushNotificationCapability))
return;

var preprocessorPath = path + "/Classes/Preprocessor.h";
var preprocessorPath = Path.Combine(path, "Classes/Preprocessor.h");
#if UNITY_6000_5_OR_NEWER
if (PlayerSettings.xcodeProjectType == XcodeProjectType.Swift)
preprocessorPath = Path.Combine(path, "UnityFramework/Prefix/Preprocessor.h");
#endif

var preprocessor = File.ReadAllText(preprocessorPath);
var needsToWriteChanges = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if UNITY_XCODE_PROJECT_TYPE_SWIFT

import Foundation

@_cdecl("UnityMobileNotifications_applicationWillFinishLaunchingName")
func applicationWillFinishLaunchingName() -> Notification.Name {
UnityNotifications.applicationWillFinishLaunching
}

@_cdecl("UnityMobileNotifications_applicationDidRegisterForRemoteNotificationsName")
func applicationDidRegisterForRemoteNotificationsName() -> Notification.Name {
UnityNotifications.applicationDidRegisterForRemoteNotifications
}

@_cdecl("UnityMobileNotifications_applicationDidFailToRegisterForRemoteNotificationsName")
func applicationDidFailToRegisterForRemoteNotificationsName() -> Notification.Name {
UnityNotifications.applicationDidFailToRegisterForRemoteNotifications
}

@_cdecl("UnityMobileNotifications_remoteNotificationsDeviceTokenKey")
func remoteNotificationsDeviceTokenKey() -> NSString {
UnityNotifications.remoteNotificationsDeviceTokenKey as NSString
}

#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
#import "UnityNotificationManager.h"

#if UNITY_XCODE_PROJECT_TYPE_SWIFT
#import "UnityFramework/UnityFramework-Swift.h"
#define kUnityWillFinishLaunchingWithOptions UnityNotifications.applicationWillFinishLaunching
#define kUnityDidRegisterForRemoteNotificationsWithDeviceToken UnityNotifications.applicationDidRegisterForRemoteNotifications
#define kUnityDidFailToRegisterForRemoteNotificationsWithError UnityNotifications.applicationDidFailToRegisterForRemoteNotifications
extern "C"
{
NSNotificationName UnityMobileNotifications_applicationWillFinishLaunchingName();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you #import UnityAPI or UnityFramework to see UnityNotifications interface here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnityAPI does not exist in 6.6 and 6.5 and it is the one you have to import in trunk. We don't have version handling yet, so I can make it work with older or newer, not both.

NSNotificationName UnityMobileNotifications_applicationDidRegisterForRemoteNotificationsName();
NSNotificationName UnityMobileNotifications_applicationDidFailToRegisterForRemoteNotificationsName();
NSString* UnityMobileNotifications_remoteNotificationsDeviceTokenKey();
}
#define kUnityWillFinishLaunchingWithOptions UnityMobileNotifications_applicationWillFinishLaunchingName()
#define kUnityDidRegisterForRemoteNotificationsWithDeviceToken UnityMobileNotifications_applicationDidRegisterForRemoteNotificationsName()
#define kUnityDidFailToRegisterForRemoteNotificationsWithError UnityMobileNotifications_applicationDidFailToRegisterForRemoteNotificationsName()
#else
#import "Classes/PluginBase/AppDelegateListener.h"
#endif
Expand Down Expand Up @@ -104,7 +110,7 @@ + (NSData*)deviceTokenFromNotification:(NSNotification*)notification
NSData* deviceToken = nil;

#if UNITY_XCODE_PROJECT_TYPE_SWIFT
id token = [notification.userInfo objectForKey: UnityNotifications.remoteNotificationsDeviceTokenKey];
id token = [notification.userInfo objectForKey: UnityMobileNotifications_remoteNotificationsDeviceTokenKey()];
#else
id token = notification.userInfo;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
#import "UnityNotificationManager.h"


int _NativeSizeof_iOSNotificationAuthorizationData()
int _NativeSizeof_iOSNotificationAuthorizationData(void)
{
return sizeof(iOSNotificationAuthorizationData);
}

int _NativeSizeof_iOSNotificationData()
int _NativeSizeof_iOSNotificationData(void)
{
return sizeof(iOSNotificationData);
}

int _NativeSizeof_NotificationSettingsData()
int _NativeSizeof_NotificationSettingsData(void)
{
return sizeof(NotificationSettingsData);
}
Expand Down Expand Up @@ -57,12 +57,12 @@ void _RequestAuthorization(void* request, int options, BOOL registerRemote)
center.delegate = manager;
}

int _RegisteredForRemoteNotifications()
int _RegisteredForRemoteNotifications(void)
{
return [UIApplication sharedApplication].registeredForRemoteNotifications;
}

void _UnregisterForRemoteNotifications()
void _UnregisterForRemoteNotifications(void)
{
UnityNotificationManager* manager = [UnityNotificationManager sharedInstance];
[manager unregisterForRemoteNotifications];
Expand All @@ -74,7 +74,7 @@ void _ScheduleLocalNotification(iOSNotificationData data)
[manager scheduleLocalNotification: &data];
}

NotificationSettingsData _GetNotificationSettings()
NotificationSettingsData _GetNotificationSettings(void)
{
UnityNotificationManager* manager = [UnityNotificationManager sharedInstance];
return UNNotificationSettingsToNotificationSettingsData(manager.cachedNotificationSettings);
Expand Down Expand Up @@ -133,7 +133,7 @@ void _RemoveScheduledNotification(const char* identifier)
[[UnityNotificationManager sharedInstance] updateScheduledNotificationList];
}

void _RemoveAllScheduledNotifications()
void _RemoveAllScheduledNotifications(void)
{
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center removeAllPendingNotificationRequests];
Expand All @@ -147,7 +147,7 @@ void _RemoveDeliveredNotification(const char* identifier)
[[UnityNotificationManager sharedInstance] updateDeliveredNotificationList];
}

void _RemoveAllDeliveredNotifications()
void _RemoveAllDeliveredNotifications(void)
{
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center removeAllDeliveredNotifications];
Expand All @@ -159,18 +159,18 @@ void _SetApplicationBadge(long badge)
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: badge];
}

long _GetApplicationBadge()
long _GetApplicationBadge(void)
{
return [UIApplication sharedApplication].applicationIconBadgeNumber;
}

int _GetAppOpenedUsingNotification()
int _GetAppOpenedUsingNotification(void)
{
UnityNotificationManager* manager = [UnityNotificationManager sharedInstance];
return manager.launchedWithNotification;
}

iOSNotificationData* _GetLastNotificationData()
iOSNotificationData* _GetLastNotificationData(void)
{
UnityNotificationManager* manager = [UnityNotificationManager sharedInstance];
UNNotification* notification = manager.lastReceivedNotification;
Expand All @@ -184,7 +184,7 @@ int _GetAppOpenedUsingNotification()
return ret;
}

const char* _GetLastRespondedNotificationAction()
const char* _GetLastRespondedNotificationAction(void)
{
UnityNotificationManager* manager = [UnityNotificationManager sharedInstance];
NSString* action = manager.lastRespondedNotificationAction;
Expand All @@ -193,7 +193,7 @@ int _GetAppOpenedUsingNotification()
return strdup(action.UTF8String);
}

const char* _GetLastRespondedNotificationUserText()
const char* _GetLastRespondedNotificationUserText(void)
{
UnityNotificationManager* manager = [UnityNotificationManager sharedInstance];
NSString* userText = manager.lastRespondedNotificationUserText;
Expand Down Expand Up @@ -351,7 +351,7 @@ void _SetNotificationCategories(void* categorySet)
[UNUserNotificationCenter.currentNotificationCenter setNotificationCategories: categories];
}

void _OpenNotificationSettings()
void _OpenNotificationSettings(void)
{
NSString* urlString;
if (@available(iOS 15.4, *))
Expand Down