Skip to content

Commit 92eebf3

Browse files
Merge pull request #42 from ParsePlatform/richardross.unity4.discontinue
Drop support for Unity 4, to support push notifications.
2 parents cf1acc8 + 1b0c247 commit 92eebf3

File tree

1 file changed

+26
-117
lines changed

1 file changed

+26
-117
lines changed

Parse/PlatformHooks.Unity.cs

100644100755
Lines changed: 26 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,36 +1023,15 @@ internal static void RegisterNetworkRequest(WWW www, Action<WWW> action) {
10231023
/// </summary>
10241024
/// <param name="action">Action to be completed when device token is received.</param>
10251025
internal static void RegisterDeviceTokenRequest(Action<byte[]> action) {
1026-
// Basically what we want to achieve here is:
1027-
// <code>
1028-
// deviceToken = UnityEngine.iOS.NotificationServices.deviceToken
1029-
// </code>
1030-
// But because we want to support backward compatibility, we're forced to use Reflection.
1031-
// We need to return to the non-reflection way once Unity 5 is stable on 95% developers use Unity 5.
1032-
1033-
// Warning (iOS Only): Unity 5 namespace for iOS notification is under `iOS.NotificationServices`,
1034-
// while Unity 4.x put them under `NotificationServices`. They're basically the same class.
1035-
Type notificationServicesType = PlatformHooks.GetTypeFromUnityEngine("iOS.NotificationServices");
1036-
if (notificationServicesType == null) {
1037-
notificationServicesType = PlatformHooks.GetTypeFromUnityEngine("NotificationServices");
1038-
}
1039-
1040-
PropertyInfo deviceTokenProperty = null;
1041-
if (notificationServicesType != null) {
1042-
deviceTokenProperty = notificationServicesType.GetProperty("deviceToken");
1043-
}
1044-
10451026
RunOnMainThread(() => {
1046-
if (deviceTokenProperty != null) {
1047-
byte[] deviceToken = (byte[])deviceTokenProperty.GetValue(null, null);
1048-
if (deviceToken != null) {
1049-
action(deviceToken);
1050-
RegisteriOSPushNotificationListener((payload) => {
1051-
ParsePush.parsePushNotificationReceived.Invoke(ParseInstallation.CurrentInstallation, new ParsePushNotificationEventArgs(payload));
1052-
});
1053-
} else {
1054-
RegisterDeviceTokenRequest(action);
1055-
}
1027+
var deviceToken = UnityEngine.iOS.NotificationServices.deviceToken;
1028+
if (deviceToken != null) {
1029+
action(deviceToken);
1030+
RegisteriOSPushNotificationListener((payload) => {
1031+
ParsePush.parsePushNotificationReceived.Invoke(ParseInstallation.CurrentInstallation, new ParsePushNotificationEventArgs(payload));
1032+
});
1033+
} else {
1034+
RegisterDeviceTokenRequest(action);
10561035
}
10571036
});
10581037
}
@@ -1062,79 +1041,26 @@ internal static void RegisterDeviceTokenRequest(Action<byte[]> action) {
10621041
/// </summary>
10631042
/// <param name="action">Action to be completed when push notification is received.</param>
10641043
internal static void RegisteriOSPushNotificationListener(Action<IDictionary<string, object>> action) {
1065-
// Basically what we want to achieve here is:
1066-
// <code>
1067-
// if (UnityEngine.iOS.NotificationServices.remoteNotificationCount > 0) {
1068-
// var remoteNotifications = UnityEngine.iOS.NotificationServices.remoteNotifications;
1069-
// foreach (var val in remoteNotifications) {
1070-
// var userInfo = val.userInfo;
1071-
// var payload = new Dictionary<string, object>();
1072-
//
1073-
// foreach (var key in userInfo.Keys) {
1074-
// payload[key.ToString()] = userInfo[key];
1075-
// }
1076-
//
1077-
// action(payload);
1078-
// }
1079-
// UnityEngine.iOS.NotificationServices.ClearRemoteNotifications();
1080-
// }
1081-
// </code>
1082-
// But because we want to support backward compatibility, we're forced to use Reflection.
1083-
// We need to return to the non-reflection way once Unity 5 is stable on 95% developers use Unity 5.
1084-
1085-
// Warning (iOS Only): Unity 5 namespace for iOS notification is under `iOS.NotificationServices`,
1086-
// while Unity 4.x put them under `NotificationServices`. They're basically the same class.
1087-
Type notificationServicesType = PlatformHooks.GetTypeFromUnityEngine("iOS.NotificationServices");
1088-
if (notificationServicesType == null) {
1089-
notificationServicesType = PlatformHooks.GetTypeFromUnityEngine("NotificationServices");
1090-
}
1091-
1092-
PropertyInfo remoteNotificationCountProperty = null;
1093-
if (notificationServicesType != null) {
1094-
remoteNotificationCountProperty = notificationServicesType.GetProperty("remoteNotificationCount");
1095-
}
1096-
1097-
MethodInfo clearRemoteNotificationsMethod = null;
1098-
PropertyInfo remoteNotificationsProperty = null;
1099-
if (notificationServicesType != null) {
1100-
clearRemoteNotificationsMethod = notificationServicesType.GetMethod("ClearRemoteNotifications");
1101-
remoteNotificationsProperty = notificationServicesType.GetProperty("remoteNotifications");
1102-
}
1103-
1104-
// Warning (iOS Only): Unity 5 namespace for iOS notification is under `iOS.RemoteNotification`,
1105-
// while Unity 4.x put them under `RemoteNotification`. They're basically the same class.
1106-
Type remoteNotificationType = PlatformHooks.GetTypeFromUnityEngine("iOS.RemoteNotification");
1107-
if (remoteNotificationType == null) {
1108-
remoteNotificationType = PlatformHooks.GetTypeFromUnityEngine("RemoteNotification");
1109-
}
1110-
1111-
PropertyInfo userInfoProperty = null;
1112-
if (remoteNotificationType != null) {
1113-
userInfoProperty = remoteNotificationType.GetProperty("userInfo");
1114-
}
1115-
11161044
RunOnMainThread(() => {
1117-
if (remoteNotificationCountProperty != null) {
1118-
int remoteNotificationCount = (int)remoteNotificationCountProperty.GetValue(null, null);
1119-
if (remoteNotificationCount > 0) {
1120-
Array remoteNotifications = (Array)remoteNotificationsProperty.GetValue(null, null);
1121-
IEnumerator enumerator = remoteNotifications.GetEnumerator();
1122-
while (enumerator.MoveNext()) {
1123-
var userInfo = (IDictionary)userInfoProperty.GetValue(enumerator.Current, null);
1124-
var payload = new Dictionary<string, object>();
1125-
foreach (var key in userInfo.Keys) {
1126-
payload[key.ToString()] = userInfo[key];
1127-
}
1128-
1129-
// Finally, do the action for each remote notification payload.
1130-
action(payload);
1045+
int remoteNotificationCount = UnityEngine.iOS.NotificationServices.remoteNotificationCount;
1046+
if (remoteNotificationCount > 0) {
1047+
var remoteNotifications = UnityEngine.iOS.NotificationServices.remoteNotifications;
1048+
foreach (var val in remoteNotifications) {
1049+
var userInfo = val.userInfo;
1050+
var payload = new Dictionary<string, object>();
1051+
foreach (var key in userInfo.Keys) {
1052+
payload[key.ToString()] = userInfo[key];
11311053
}
11321054

1133-
clearRemoteNotificationsMethod.Invoke(null, null);
1055+
// Finally, do the action for each remote notification payload.
1056+
action(payload);
11341057
}
1135-
// Check in every frame.
1136-
RegisteriOSPushNotificationListener(action);
1058+
1059+
UnityEngine.iOS.NotificationServices.ClearRemoteNotifications();
11371060
}
1061+
1062+
// Check in every frame.
1063+
RegisteriOSPushNotificationListener(action);
11381064
});
11391065
}
11401066

@@ -1203,26 +1129,9 @@ public void Initialize() {
12031129
// from main thread.
12041130
isWebPlayer = Application.isWebPlayer;
12051131
osVersion = SystemInfo.deviceModel;
1206-
// Unity 5 has `Application.version`, but will compile-error in earlier version.
1207-
// Reflection is the best way we can do for now.
1208-
PropertyInfo appVersionProp = typeof(Application).GetProperty("version");
1209-
if (appVersionProp != null) {
1210-
appBuildVersion = (string)appVersionProp.GetValue(null, null);
1211-
}
1212-
1213-
// Unity 5 has `Application.bundleIdentifier`, but will compile error in earlier version.
1214-
// Reflection is the best way we can do for now.
1215-
PropertyInfo bundleIdProp = typeof(Application).GetProperty("bundleIdentifier");
1216-
if (bundleIdProp != null) {
1217-
appDisplayVersion = (string)bundleIdProp.GetValue(null, null);
1218-
}
1219-
1220-
// Unity 5 has `Application.productName`, but will compile error in earlier version.
1221-
// Reflection is the best way we can do for now.
1222-
PropertyInfo productNameProp = typeof(Application).GetProperty("productName");
1223-
if (productNameProp != null) {
1224-
appName = (string)productNameProp.GetValue(null, null);
1225-
}
1132+
appBuildVersion = Application.version;
1133+
appDisplayVersion = Application.bundleIdentifier;
1134+
appName = Application.productName;
12261135

12271136
settings = SettingsWrapper.Wrapper;
12281137

0 commit comments

Comments
 (0)