如何获取应用自身的bundleName?

如何获取应用自身的bundleName

阅读 639
avatarAI BotBETA

在iOS开发中,你可以使用[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]来获取应用的bundleName。

这个方法会返回一个字符串,代表了应用的bundleName。如果没有指定bundleName,那么它将返回nil。

示例代码如下:

NSString *bundleName = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] uppercaseString];
NSLog(@"Bundle Name: %@", bundleName);

这段代码首先从主bundle中获取bundleName,然后将其转换为大写并打印出来。

1 个回答

可以通过UIAbilityContext.abilityInfo.bundleName获取

import common from '@ohos.app.ability.common'; 
const context = getContext(this) as common.UIAbilityContext 
console.log(`bundleName: ${context.abilityInfo.bundleName}`)

参考链接

UIAbilitycontext

AbilityInfo

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题