@@ -1023,36 +1023,15 @@ internal static void RegisterNetworkRequest(WWW www, Action<WWW> action) {
1023
1023
/// </summary>
1024
1024
/// <param name="action">Action to be completed when device token is received.</param>
1025
1025
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
-
1045
1026
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 ) ;
1056
1035
}
1057
1036
} ) ;
1058
1037
}
@@ -1062,79 +1041,26 @@ internal static void RegisterDeviceTokenRequest(Action<byte[]> action) {
1062
1041
/// </summary>
1063
1042
/// <param name="action">Action to be completed when push notification is received.</param>
1064
1043
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
-
1116
1044
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 ] ;
1131
1053
}
1132
1054
1133
- clearRemoteNotificationsMethod . Invoke ( null , null ) ;
1055
+ // Finally, do the action for each remote notification payload.
1056
+ action ( payload ) ;
1134
1057
}
1135
- // Check in every frame.
1136
- RegisteriOSPushNotificationListener ( action ) ;
1058
+
1059
+ UnityEngine . iOS . NotificationServices . ClearRemoteNotifications ( ) ;
1137
1060
}
1061
+
1062
+ // Check in every frame.
1063
+ RegisteriOSPushNotificationListener ( action ) ;
1138
1064
} ) ;
1139
1065
}
1140
1066
@@ -1203,26 +1129,9 @@ public void Initialize() {
1203
1129
// from main thread.
1204
1130
isWebPlayer = Application . isWebPlayer ;
1205
1131
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 ;
1226
1135
1227
1136
settings = SettingsWrapper . Wrapper ;
1228
1137
0 commit comments