Skip to content
Open
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
20 changes: 19 additions & 1 deletion scripts/ios/custom-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ if (rootdir) {
return path.join(projectRoot, "platforms", platform, cfg.name(), relPath);
};

var appendTo = function(path, methodHeader, implementation) {
var data = fs.readFileSync(path, "utf8");
var indexOfMethodHeader = data.indexOf(methodHeader);
if (indexOfMethodHeader == -1) {
return false;
}
var result = data.replace(methodHeader, methodHeader + '\n' + implementation);
fs.writeFileSync(path, result, "utf8");
return true;
};

var replace = function(path, to_replace, replace_with) {
var data = fs.readFileSync(path, "utf8");
var result = data.replace(to_replace, replace_with);
Expand All @@ -31,7 +42,14 @@ if (rootdir) {
var finishLaunchingReplace = "/* HOOK: applicationDidFinishLaunching */";
replace(appDelegate, importReplace, "#import \"ESFBMessaging.h\"\n" + importReplace);
replace(appDelegate, finishLaunchingReplace, "[ESFBMessaging setLaunchData:launchOptions];\n\t" + finishLaunchingReplace);
replace(appDelegate, "@end", "- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {" + "\n\t" + "[ESFBMessaging notificationReceived:userInfo];" + "\n\t" + "completionHandler(UIBackgroundFetchResultNewData);\n}" + "\n\n" + "@end")


var header = "- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler {";
var implementation = "\t[ESFBMessaging notificationReceived:userInfo];" + "\n\t" + "completionHandler(UIBackgroundFetchResultNewData);\n";
var method = header + "\n" + "\t[ESFBMessaging notificationReceived:userInfo];\n" + '}';
if (!appendTo(appDelegate, header, implementation)) {
replace(appDelegate, "@end", method + "\n" + "@end");
}
};

updateIOSAppDelegate();
Expand Down