@@ -46,6 +46,7 @@ public static class BuildPostProcessor
46
46
{
47
47
public static readonly string DEFAULT_PROJECT_TARGET_NAME = "Unity-iPhone" ;
48
48
public static readonly string NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME = "OneSignalNotificationServiceExtension" ;
49
+ public static readonly string NOTIFICATION_SERVICE_EXTENSION_OBJECTIVEC_FILENAME = "NotificationService" ;
49
50
50
51
private static readonly char DIR_CHAR = Path . DirectorySeparatorChar ;
51
52
public static readonly string OS_PLATFORM_LOCATION = "Assets" + DIR_CHAR + "OneSignal" + DIR_CHAR + "Platforms" + DIR_CHAR ;
@@ -211,7 +212,7 @@ private static void AddPushCapability(PBXProject project, string path, string ta
211
212
212
213
private static void AddNotificationServiceExtension ( PBXProject project , string path )
213
214
{
214
- #if UNITY_2017_2_OR_NEWER && ! UNITY_CLOUD_BUILD
215
+ #if UNITY_2017_2_OR_NEWER && ! UNITY_CLOUD_BUILD
215
216
var projectPath = PBXProject . GetPBXProjectPath ( path ) ;
216
217
var mainTargetGUID = GetPBXProjectTargetGUID ( project ) ;
217
218
var extensionTargetName = NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME ;
@@ -231,9 +232,7 @@ private static void AddNotificationServiceExtension(PBXProject project, string p
231
232
extensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode
232
233
) ;
233
234
234
- var sourceDestination = extensionTargetName + "/NotificationService" ;
235
- project . AddFileToBuild ( extensionGUID , project . AddFile ( sourceDestination + ".h" , sourceDestination + ".h" , PBXSourceTree . Source ) ) ;
236
- project . AddFileToBuild ( extensionGUID , project . AddFile ( sourceDestination + ".m" , sourceDestination + ".m" , PBXSourceTree . Source ) ) ;
235
+ AddNotificationServiceSourceFilesToTarget ( project , extensionGUID , path ) ;
237
236
238
237
foreach ( var framework in FRAMEWORKS_TO_ADD ) {
239
238
project . AddFrameworkToProject ( extensionGUID , framework , true ) ;
@@ -245,10 +244,6 @@ private static void AddNotificationServiceExtension(PBXProject project, string p
245
244
246
245
project . SetBuildProperty ( extensionGUID , "ARCHS" , "$(ARCHS_STANDARD)" ) ;
247
246
project . SetBuildProperty ( extensionGUID , "DEVELOPMENT_TEAM" , PlayerSettings . iOS . appleDeveloperTeamID ) ;
248
-
249
- foreach ( var type in new string [ ] { "m" , "h" } )
250
- if ( ! File . Exists ( path + DIR_CHAR + sourceDestination + "." + type ) )
251
- FileUtil . CopyFileOrDirectory ( OS_PLATFORM_LOCATION + "iOS" + DIR_CHAR + "NotificationService." + type , path + DIR_CHAR + sourceDestination + "." + type ) ;
252
247
253
248
project . AddBuildProperty ( extensionGUID , "LIBRARY_SEARCH_PATHS" , "$(PROJECT_DIR)/Libraries/OneSignal/Platforms/iOS" ) ;
254
249
project . WriteToFile ( projectPath ) ;
@@ -268,8 +263,26 @@ private static void AddNotificationServiceExtension(PBXProject project, string p
268
263
extensionTargetName ,
269
264
new HashSet < EntitlementOptions > { EntitlementOptions . AppGroups }
270
265
) ;
271
- #endif
266
+ #endif
267
+ }
268
+
269
+ // Copies NotificationService.m and .h files into the OneSignalNotificationServiceExtension folder adds them to the Xcode target
270
+ private static void AddNotificationServiceSourceFilesToTarget ( PBXProject project , string extensionGUID , string path )
271
+ {
272
+ var buildPhaseID = project . AddSourcesBuildPhase ( extensionGUID ) ;
273
+ foreach ( var type in new string [ ] { "m" , "h" } ) {
274
+ var nativeFileName = NOTIFICATION_SERVICE_EXTENSION_OBJECTIVEC_FILENAME + "." + type ;
275
+ var sourcePath = OS_PLATFORM_LOCATION + "iOS" + DIR_CHAR + nativeFileName ;
276
+ var nativeFileRelativeDestination = NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME + "/" + nativeFileName ;
277
+
278
+ var destPath = path + DIR_CHAR + nativeFileRelativeDestination ;
279
+ if ( ! File . Exists ( destPath ) )
280
+ FileUtil . CopyFileOrDirectory ( sourcePath , destPath ) ;
281
+
282
+ var sourceFileGUID = project . AddFile ( nativeFileRelativeDestination , nativeFileRelativeDestination , PBXSourceTree . Source ) ;
283
+ project . AddFileToBuildSection ( extensionGUID , buildPhaseID , sourceFileGUID ) ;
272
284
}
285
+ }
273
286
274
287
// Create a .plist file for the NSE
275
288
// NOTE: File in Xcode project is replaced everytime, never appends
0 commit comments