FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update HOWTO with NativeScriptEmbedderDelegate protocol usage instructions by tdermendjiev · Pull Request #10 · NativeScript/sample-ios-embedded · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .PNG  (1) .h  (1) .json  (1) .m  (1) .md  (1) .pbxproj  (1) All 6 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 20 additions & 2 deletions CoolApp/CoolApp.xcodeproj/project.pbxproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
040D38BB1F8CB8EA00644DEA /* NativeScript.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 040D38BA1F8CB8E900644DEA /* NativeScript.framework */; };
040D38BE1F8CBAFF00644DEA /* NativeScript.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 040D38BA1F8CB8E900644DEA /* NativeScript.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
040D38BF1F8CBB0400644DEA /* TNSWidgets.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 040D38B81F8CB84D00644DEA /* TNSWidgets.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
9306F9B6212569F3009778A5 /* NativeScriptEmbedder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9306F9B5212569F3009778A5 /* NativeScriptEmbedder.m */; };
DFA19F5481B50A881A42CD73 /* Pods_CoolApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 553CE055441751191B8D0863 /* Pods_CoolApp.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -53,6 +54,7 @@
553CE055441751191B8D0863 /* Pods_CoolApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_CoolApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
77FC8B2111566679B1B8699F /* Pods-CoolApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoolApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CoolApp/Pods-CoolApp.debug.xcconfig"; sourceTree = "<group>"; };
809CED86F5631804511288F5 /* Pods-CoolApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoolApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-CoolApp/Pods-CoolApp.release.xcconfig"; sourceTree = "<group>"; };
9306F9B5212569F3009778A5 /* NativeScriptEmbedder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = NativeScriptEmbedder.m; path = "../nsapp/node_modules/tns-core-modules/platforms/ios/src/NativeScriptEmbedder.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -72,6 +74,7 @@
040D38931F8CA8AB00644DEA = {
isa = PBXGroup;
children = (
9306F9B5212569F3009778A5 /* NativeScriptEmbedder.m */,
040D389E1F8CA8AB00644DEA /* CoolApp */,
040D389D1F8CA8AB00644DEA /* Products */,
040D38B71F8CB84C00644DEA /* Frameworks */,
Expand Down Expand Up @@ -253,6 +256,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9306F9B6212569F3009778A5 /* NativeScriptEmbedder.m in Sources */,
040D38A41F8CA8AB00644DEA /* ViewController.m in Sources */,
040D38AF1F8CA8AB00644DEA /* main.m in Sources */,
040D38A11F8CA8AB00644DEA /* AppDelegate.m in Sources */,
Expand Down Expand Up @@ -399,9 +403,16 @@
"$(inherited)",
"$(PROJECT_DIR)/../nsapp/node_modules/tns-core-modules-widgets/platforms/ios",
);
HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../nsapp/node_modules/tns-core-modules/platforms/ios/src";
INFOPLIST_FILE = CoolApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
"OTHER_LDFLAGS[arch=*]" = "-sectcreate __DATA __TNSMetadata \"$(CONFIGURATION_BUILD_DIR)/metadata-$(CURRENT_ARCH).bin\" $(inherited)";
"OTHER_LDFLAGS[arch=*]" = (
"-sectcreate",
__DATA,
__TNSMetadata,
"\"$(CONFIGURATION_BUILD_DIR)/metadata-$(CURRENT_ARCH).bin\"",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = com.mastertechapps.CoolApp;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -422,9 +433,16 @@
"$(inherited)",
"$(PROJECT_DIR)/../nsapp/node_modules/tns-core-modules-widgets/platforms/ios",
);
HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/../nsapp/node_modules/tns-core-modules/platforms/ios/src";
INFOPLIST_FILE = CoolApp/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
"OTHER_LDFLAGS[arch=*]" = "-sectcreate __DATA __TNSMetadata \"$(CONFIGURATION_BUILD_DIR)/metadata-$(CURRENT_ARCH).bin\" $(inherited)";
"OTHER_LDFLAGS[arch=*]" = (
"-sectcreate",
__DATA,
__TNSMetadata,
"\"$(CONFIGURATION_BUILD_DIR)/metadata-$(CURRENT_ARCH).bin\"",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = com.mastertechapps.CoolApp;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
3 changes: 2 additions & 1 deletion CoolApp/CoolApp/ViewController.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
//

#import <UIKit/UIKit.h>
#import "NativeScriptEmbedder.h"

@interface ViewController : UIViewController
@interface ViewController : UIViewController <NativeScriptEmbedderDelegate>

- (IBAction)activateNativeScript:(id)sender;

Expand Down
7 changes: 7 additions & 0 deletions CoolApp/CoolApp/ViewController.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ - (void)viewDidLoad {
[super viewDidLoad];
counter=0;
[self _initializeRuntime];

[NativeScriptEmbedder sharedInstance].delegate = self;
}

- (void)_initializeRuntime {
Expand Down Expand Up @@ -170,5 +172,10 @@ - (void) receiveNativeScriptNotification:(NSNotification *) notification

}

- (id)presentNativeScriptApp: (UIViewController*) vc {
[self presentViewController:vc animated:YES completion:NULL];
return 0;
}

@end

42 changes: 39 additions & 3 deletions HOWTO.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,47 @@ From inside NativeScript the code looks like this:
}
```

## Potential Gotchas and Issues
## The NativeScriptEmbedderDelegate protocol
NativeScript 4.2.0 gives embedders more control over the NativeScript application using the *NativeScriptEmbedder* class and the *NativeScriptEmbedderDelegate* protocol. In order to take advantage of them you need to do few additional steps:

1. The embedded NativeScript view is currently full screen; there is no easy way to currently embed it as a sub-view of your view. To embed it as a sub-view would require you to modify the application.js, page.js, and frame.js classes inside NativeScript. Not something that would be quick and easy. It is possible, but would take a bit of work.
1. Add *tns-core-modules* **src** folder to your **Header Search Paths**:

```
$(PROJECT_DIR)/../nsapp/node_modules/tns-core-modules/platforms/ios/src
```
2. Add **NativeScriptEmbedder.m** file to **Compile Sources**(*Build Phases -> Compile Sources*)

![docs/nativescript_embedder.PNG](docs/nativescript_embedder.PNG)

3. Update the class you want to get a reference to the NativeScript app *rootViewController* to conform to the **NativeScriptEmbedderDelegate** protocol. For example:

```
@interface ViewController () <NativeScriptEmbedderDelegate>

@end
```

4. Register the delegate (e.g. in **viewDidLoad**):

```
[NativeScriptEmbedder sharedInstance].delegate = self;
```

5. Implement **NativeScriptEmbedderDelegate** protocol's **presentNativeScriptApp:** method:

```
- (id)presentNativeScriptApp: (UIViewController*) vc {
[self addChildViewController:vc];
[vc.view setFrame:_containerView.bounds];
[_containerView addSubview:vc.view];
[vc didMoveToParentViewController:self];
return 0;
}
```
Here **_containerView** is the view we want to add our NativeScript app to and **vc** is the embedded app's *rootViewController*.

>Note that **presentNativeScriptApp:** method returns **0**. This is required due to a limitation in the current runtime's logic.

2. NativeScript has a **"launch"** event which you can use. This event does NOT work in embedded mode. As a side effect of this event not working in embedded mode, the standard global **&quot;app.css&quot;** is never loaded. This css file is used for all your common css. For you to have a common **.css** file; I recommend you add the following line to each of your screen's css file **@import 'app.css';** this will cause your screen to load the global app.css file when it is loaded. There are other ways around this; but this is the simplest method to retain the use of a common css file.

## Go Forth and Embed!

Expand Down
Binary file added docs/nativescript_embedder.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
6 changes: 3 additions & 3 deletions nsapp/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"nativescript": {
"id": "org.nativescript.nsapp",
"tns-ios": {
"version": "4.1.0"
"version": "4.2.0"
}
},
"dependencies": {
"nativescript-drawingpad": "^3.0.3",
"nativescript-theme-core": "~1.0.4",
"tns-core-modules": "^4.1.0"
"tns-core-modules": "^4.2.0"
}
}
}

Back | FazBrowse Home | New Git URL