I already had run react-native start and then react-native run-ios. So my app is running.
I placed ios-glyphs.ttf into a folder called fonts in my root directory. So ./fonts. I then added to package.json this:
"rnpm": {
"assets": [
"fonts"
]
}
I then ran react-native link.
After that in my app I added in a rende:
<Text style={{fontFamily:'ios-glyphs'}}></Text>
On load of my app it is fine, but when i load the page that renders this custom font I get "Unrecognized font family 'ios-glyphs'", here is a screenshot: http://i.imgur.com/G6hwlor.png
The page does load after dismissing that error but the icon looks like a question mark in a box but my real icon is a star:
I then did some funky stuff. I thought I linked it wrong so I changed the folder path, and moved font to new folder and linked again. Then I went into xcode and saw two of them in "Resources" so I deleted the first one as that folder was no longer there.
Does anyone know how to fix this error? Should I throw discard this commit? Will it make it like I never linked anything? I'm worried I might have screwed up my project with xcode.
Thanks very much to #sfratini - React-Native can't resolve module for fonts - the font name was actually totally different then file name, as hinted by the tutorial.
How I found the real font name was by following #sfratini's instructions.
I opened up xcode, and opened the ios folder in my project folder with xcode, like this.
I then added to AppDelegate.m this code:
NSArray *families = [[UIFont familyNames] sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
NSMutableString *fonts = [NSMutableString string];
for (int i = 0; i < [families count]; i++) {
[fonts appendString:[NSString stringWithFormat:#"\n%#:\n", families[i]]];
NSArray *names = [UIFont fontNamesForFamilyName:families[i]];
for (int j = 0; j < [names count]; j++) {
[fonts appendString:[NSString stringWithFormat:#"\t%#\n", names[j]]];
}
}
NSLog(#"%#", fonts);
Then found the new icon name in the console log.
My project folder:
Open with xcode:
Click on the folders, then add to AppDelegate.m the code then save and either run react-native run-ios or press "Play" button as in screenshot below (You need to recompile, I doubt hot reloading will work but I didn't test):
Then a full list of font names get spit out in the console log:
I did the fonts before linking, then after linking, and did a diff to find my font names.
Related
When trying to build a native module from Xcode and importing RCTUIManager (#import "React/RCTUIManager.h") I am getting a lot of errors related to RCTBridgeModule. The errors are:
"Redefinition of RCTMethodInfo"
"Cannot find protocol declaration for "RCTBridgeModule" and other errors
If I don't import RCTUIManager everything works fine, but I need this for using:
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
UIView *view = viewRegistry[[NSNumber numberWithInt:tagId]];
if (![view isKindOfClass:[UIView class]]) {
RCTLog(#"expecting UIView, got: %#", view);
}
else {
}
}];
How can I get rid of this errors? I am using the latest version of React Native (0.57.8) and Xcode (10.2).
Try with #import <React/RCTUIManager.h>?
Also it would be a good idea to clean the project before building. You can do that selecting Product -> Clean Build Folder or by pressing CMD SHIFT and K.
Trying to create my first npm module in order to determine if a user is on the phone. It's for a React Native app. No matter what I try, the module returns undefined. NativeModules always appears to be an empty object.
Please help! Below is a link to the code. export default RNOnPhoneCall; in index.js will only return undefined. How do I link the functions in ios folder, and export them in index.js? Heads up, android is not up to date yet, only ios.
Link to Github
After snooping around a little, I found out that the Obj-C file isn't added to the Compile Sources in Xcode. Just follow me:
Let's say the file names are: NotchNative.h and NotchNative.m. If the NotchNative.m file is not listed, the files will not be compiled by Xcode hence it needs to be added to the Compile Sources.
Follow the steps in the image and rebuild/run the iOS app again.
It's surely a fault on the Xcode side, as it doesn't happen in case of Swift projects.
Try rebuilding your project. I faced the same issue recently and simply rebuilding resolved it
I was not exporting the method correctly in my iOS file. Here's the solution, along with a link to the final project.
react-native-check-phone-call-status on github
#import "RNCheckPhoneCallStatus.h"
#import "React/RCTLog.h"
#import <AVFoundation/AVAudioSession.h>
#import<CoreTelephony/CTCallCenter.h>
#import<CoreTelephony/CTCall.h>
#implementation RNCheckPhoneCallStatus
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(get:(RCTResponseSenderBlock)callback)
{
NSString *phoneStatus = #"PHONE_OFF";
CTCallCenter *ctCallCenter = [[CTCallCenter alloc] init];
if (ctCallCenter.currentCalls != nil)
{
NSArray* currentCalls = [ctCallCenter.currentCalls allObjects];
for (CTCall *call in currentCalls)
{
if(call.callState == CTCallStateConnected)
{
phoneStatus = #"PHONE_ON";
}
}
}
callback(#[[NSNull null], phoneStatus]);
}
#end
I am able to load a custom font in an iOS project and see it on the available fonts using:
NSArray *fontFamilies = [UIFont familyNames];
for (int i=0; i<[fontFamilies count]; i++)
{
NSLog(#"Font: %# ...", [fontFamilies objectAtIndex:i]);
}
But when I try and load the font into the OSX project, I am not able to see it in the list when I display the fonts:
NSLog(#"%#",[[[NSFontManager sharedFontManager] availableFontFamilies] description]);
I used: Unable to set custom font for the UILabel in XCode to install the font for iOS project and assumed it should be the same approach for the OSX project.
The link to the font file is in the bundle resources, Info.plist file(add: Fonts provided by application), and the file is in the Supporting files.
Am I missing something? thx
I solved it programmatically(but would prefer the approach like iOS approach in the link above):
NSString* path = [[NSBundle mainBundle] pathForResource:#"Symbola" ofType:#"ttf"];
NSURL* fontsURL = [NSURL fileURLWithPath:path];
FSRef fsRef;
CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
ATSFontActivateFromFileReference(&fsRef, kATSFontContextLocal, kATSFontFormatUnspecified,
NULL, kATSOptionFlagsDefault, NULL);
I have written an OSX app that uses iCloud document storage. Whenever I open it in Mountain Lion (not on Lion), an iCloud window opens that looks like the following:
Is there a way to prevent this from happening on launch?
Updates:
1) applicationShouldOpenUntitledFile: is not getting called (yes, I'm sure I'm listening in my delegate.
2) If I force quit the app, the next time it opens, I don't get the dialog. But, if I go through the normal Quit process, it does appear.
Update 2 (also added as an answer, to help people that may stumble across this question in the future):
The applicationShouldOpenUntitledFile: from the duplicate question was not working. After lots of experimentation, I figured out that if I remove the NSDocumentClass key and value from my Info.plist in the CFBundleDocumentTypes array, the window is no longer opened. I've added that answer to the duplicate question as well.
Putting below codes in your App Delegate lets you bypass that iCloud pop up New Document screen. Tested for High Sierra.
-(void)applicationDidFinishLaunching:(NSNotification *)notification
{
// Schedule "Checking whether document exists." into next UI Loop.
// Because document is not restored yet.
// So we don't know what do we have to create new one.
// Opened document can be identified here. (double click document file)
NSInvocationOperation* op = [[NSInvocationOperation alloc]initWithTarget:self selector:#selector(openNewDocumentIfNeeded) object:nil];
[[NSOperationQueue mainQueue] addOperation: op];
}
-(void)openNewDocumentIfNeeded
{
NSUInteger documentCount = [[[NSDocumentController sharedDocumentController] documents]count];
// Open an untitled document what if there is no document. (restored, opened).
if(documentCount == 0){
[[NSDocumentController sharedDocumentController]openUntitledDocumentAndDisplay:YES error: nil];
}
}
The applicationShouldOpenUntitledFile: from iCloud enabled - Stop the open file displaying on application launch? was not working. After lots of experimentation, I figured out that if I remove the NSDocumentClass key and value from my Info.plist in the CFBundleDocumentTypes array, the window is no longer opened.
Does anyone know of tutorials or existing projects for Airstash SDK iOS integration? I have the frameworks in my project, but the existing comments inside the header files aren't incredibly helpful for initial setup. I've been googling for one, but I get a deluge of tech announcement news instead of developer resources.
-Background-
The Airstash is going to be used with an already-developed iPad application that sets equipment preferences. The targeted equipment has already been developed and has no wireless connectivity, but does have USB capability. The proposed solution is to wirelessly upload files from the iPad to an Airstash connected to the equipment.
In the SDK release there are two directories: AirStashSDK and sdk-demo. The sdk-demo directory contains an XCode project that demonstrates usage of the SDK.
The AirStashSDK folder contains the AirStash.framework to include in your project, and a Resources folder that contains a couple xib files that you should include in your project and may customize. If you plan to customize these files you may want to copy them to a different directory so your changes are not lost if you update to a newer release of the SDK. The xib files are used to display progress while getting a file from the AirStash, or activity when saving a file to the AirStash.
To save a file to an AirStash, look at the saveFileAction: method in sdk-demo/AirStashSDK Demo/RootViewController.m.
- (void)saveFileAction:(NSString*)filename
{
NSLog(#"Save a file to AirStash. filename: %#", filename);
NSURL *docDir = [self getDocumentsDirectory];
NSString *filepath = [[docDir URLByAppendingPathComponent:filename] path];
airstash = [[AirStash alloc] init];
// Save is very simple.
[airstash saveFileToAirStash:filepath
presentingFrom:self
successBlock:^(void){
NSString *msg = [NSString stringWithFormat:#"Success saving file to AirStash: original filename: %#", filename];
NSLog(#"%#", msg);
[self presentAlertWithMessage:msg];
self.airstash = nil;
}
errorBlock:^(AirStashStatus errorCode, NSString *reason) {
NSString *msg = [NSString stringWithFormat:#"Problem saving file to AirStash: (%d) %#", errorCode, reason];
NSLog(#"%#", msg);
[self presentAlertWithMessage:msg];
self.airstash = nil;
}];
}
The demo app presents a list of the files in the app's documents directory. If the user taps on a file, it calls the saveFileAction: method to save the selected file to an AirStash. An app can allocate an AirStash object and make multiple calls to its methods, or as in this case, it just makes the one call and then releases it. (The demo app's presentAlertWithMessage: method just pops up a UIAlertView with the given message and an OK button so you can see that the action is complete.)
The demo app has a couple other buttons, one to get a file from an AirStash (and save it to the app's documents directory), and the other to get the URL of a file on an AirStash. The method used by the second button would be useful for apps that want to stream a file rather than download the whole thing at once.