我是新手.当我正在学习基础知识时,我得到了这个错误NSLog
这是我的代码:
import UIKit
class ViewController: UIViewController {
var myString: NSString?
override func viewDidLoad() {
super.viewDidLoad()
myString = "himanth"
print(myString)
NSLog("%@" , myString)
// Do any additional ssetup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
如果我这样宣布的myString
话
var myString: NSString!
Run Code Online (Sandbox Code Playgroud)
它很好用NSLog
,我也可以看到控制台.
但是声明这样的字符串会导致问题
var myString: NSString?
Run Code Online (Sandbox Code Playgroud)
它反映NSLog
并显示错误.
有什么问题?
我在为我正在处理的iOS应用程序实现相机View Controller时遇到问题.当按下一个按钮时,我有一个单独的相机对象来管理AVFoundation
事物的一面并捕获图像.如下所示,一旦UIImage
从相机捕获,我就会通过一个使用它的完成块.
下面的第一种方法是在相机上按下捕获按钮时触发的动作.首先,通过禁用预览图层上的连接暂停摄像机图层,然后捕获图像.然后,相机对象捕获UIImage
,此时我从视图中移除相机预览图层,而是UIImageView
在其位置添加捕获图像的子视图.
接下来,我想使用Photos框架将图像添加到我在Photos中创建的相册中.我可以毫无问题地创建相册,并且我已经验证了该PHAssetCollection
对象.我在第二种方法中使用的是正确的方法.
但是,出于某种原因,我无法将UIImage
I capture 添加到相册中.我尝试将我项目中的随机图像文件添加到相册中,操作成功完成.我还验证了addPhotoToSavedPhotos
通过使用NSLog
语句检查两种方法中的图像描述,成功传递了正确的图像.这让我相信图像不知何故出了问题,但是imageView成功地显示了它,所以我不确定它可能是什么.
如果有人对我可能会尝试的解决方案有任何想法,我将不胜感激.另外error.localizedDescription
从NSLog
第二种方法中的语句输出"The operation couldn't be completed
.(可可错误-1)."
- (IBAction)capturePhoto:(id)sender {
[self pauseCameraLayer];
[[eventCamera sharedInstance] captureStillUIImage:^(UIImage *image, NSError *error){
if(error)
{
NSLog(@"error capturing photo");
}
else
{
NSLog(@"%@",image.debugDescription);
}
[_captureButton setHidden:YES];
[_switchCameraButton setHidden:YES];
UIImageView *preview=[[UIImageView alloc] initWithImage:image];
[preview setAutoresizesSubviews:YES];
[preview setContentMode:UIViewContentModeScaleAspectFit];
[preview setTransform:CGAffineTransformMakeRotation(M_PI_2)];
preview.frame=_imageView.bounds;
[_imageView addSubview:preview];
[self addPhotoToSavedPhotos:[image copy]];
NSLog(@"1: %@",image.description);
}];
-(void)addPhotoToSavedPhotos:(UIImage*)photo
{ …
Run Code Online (Sandbox Code Playgroud) 我已在我的应用中实施了Firebase云消息,用于推送通知.一切正常.但是通知甚至可以从应用程序注销用户.
我听说,当用户从应用程序注销时,我需要删除FCM令牌.
所以我在注销方法中这样做:
-(void)logout{
[[FIRInstanceID instanceID] deleteIDWithHandler:^(NSError *error){
NSLog(@"%@",error);
}];
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,下次用户登录时 [[FIRInstanceID instanceID]token]
即将发布null
.
这该怎么做?
我已经为我的应用程序集成了推送通知。为了捕捉通知,我使用了这个委托。
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
在我的应用程序委托中。
所以当应用程序在后台运行时,如果通知来了,当我点击它时,这个委托就会触发。如果应用程序即使在后台也没有运行,如果点击 ntification 然后它会触发
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
到目前为止它运作良好。然后我想在后台捕捉通知。所以我发现
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
这对它有用。
所以我只是将我以前的didReceive
方法更改为这种新didReceive
方法。现在我的问题是当应用程序通过推送通知启动时(如果应用程序不在后台或前台运行,并且当出现时单击通知)我的应用程序崩溃。即使我无法调试和捕捉这种情况。
这两个代表有什么区别。当应用程序通过通知启动时,我的第二个代表是否会触发?请帮我。
我正在使用FCM(Firebase云消息传递)在iOS中发送推送通知.
当App处于前台状态时,我能够收到通知.但是当应用程序处于后台状态时,不会收到通知.每当应用程序进入前台状态时,只有那时才会收到通知.
我的代码是:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
// Print message ID.
NSDictionary *userInfo = notification.request.content.userInfo;
NSLog(@"Message ID: %@", userInfo[@"gcm.message_id"]);
// Pring full message.
NSLog(@"%@", userInfo);
if( [UIApplication sharedApplication].applicationState == UIApplicationStateInactive )
{
NSLog( @"INACTIVE" );
completionHandler(UNNotificationPresentationOptionAlert);
}
else if( [UIApplication sharedApplication].applicationState == UIApplicationStateBackground )
{
NSLog( @"BACKGROUND" );
completionHandler( UNNotificationPresentationOptionAlert );
}
else
{
NSLog( @"FOREGROUND" );
completionHandler( UNNotificationPresentationOptionAlert );
}}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
Run Code Online (Sandbox Code Playgroud)
当App处于后台状态时:
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
Run Code Online (Sandbox Code Playgroud)
- 根本没有被召唤. …
objective-c ios firebase firebase-cloud-messaging firebase-notifications
将Xcode版本更新为8.0后,我收到此错误.在尝试注册远程通知时,我可以在我的日志中看到这样的内容
Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo={NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}, no valid 'aps-environment' entitlement string found for application
Run Code Online (Sandbox Code Playgroud)
我尝试了一些与我的问题相关的Stack Overflow答案,但无法解决这个问题.
1.处理新的临时简介
2.删除并重新安装应用程序
3.手动设置临时配置文件.
以上任何一项都没有帮助我解决.
请给我一些建议.提前致谢.
我有这样的数组
( {
GPSOdometerReading = "11843.6";
"_id" = {
"$oid" = 5656e7175201edbb16a483f4;
};
acc = 0;
)
Run Code Online (Sandbox Code Playgroud)
那么如何知道我的数组是否包含字典?
谢谢.
我正在AFNetworking
我的项目中使用来从REST api获取数据.但是当我使用Github中描述的方法时,我会收到警告.
这是我的代码:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"http://httpbin.org/get"];
NSURLRequest *request123 = [NSURLRequest requestWithURL:URL];
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request123 completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"%@ %@", response, responseObject);
}
}];
[dataTask resume];
Run Code Online (Sandbox Code Playgroud)
我的项目支持iOS 7.0及更高版本.
我的Xcode版本7.3.1
有没有办法克服这个警告?
我想知道哪些架构支持我的框架.
我提到了一些堆栈溢出问题,并在终端中尝试了这样
lipo -info /Users/admin/library/myFramework.framework
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何解决方案.
如何解决我的问题.
嗨,我是iOS开发的新手.我想获得响应并将这些值添加到变量中.
我尝试了但是我的反应低于预期.我不明白为什么这个回复中有斜杠.
@"[{\"VisitorID\":\"2864983a-e26b-441a-aedf-84e2a1770b8e\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kanasalingam\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]},{\"VisitorID\":\"133bc108-b3bf-468a-9397-e1b0dba449db\",\"ProfileID\":\"69c02265-abca-4716-8a2f-ac5d642f876a\",\"CompanyID\":null,\"VisitorName\":\"kumar\",\"OperatorName\":\"baman\",\"Image\":null,\"isocode\":\"lk\",\"CurrentOperator\":[\"69c02265-abca-4716-8a2f-ac5d642f876a\"]}]"
Run Code Online (Sandbox Code Playgroud)
我试过这个:
- (void) sendOtherActiveChats:(NSDictionary *) chatDetails{
NSLog(@"inside sendOtherActiveChats");
NSLog(@"otherDetails Dictionary : %@ ", chatDetails);
NSString *VisitorID = [chatDetails objectForKey:@"VisitorID"];
NSString *ProfileID = [chatDetails objectForKey:@"ProfileID"];
NSString *CompanyID = [chatDetails objectForKey:@"CompanyID"];
NSString *VisitorName = [chatDetails objectForKey:@"VisitorName"];
NSString *OperatorName = [chatDetails objectForKey:@"OperatorName"];
NSString *isocode = [chatDetails objectForKey:@"isocode"];
NSLog(@"------------------------Other Active Chats -----------------------------------");
NSLog(@"VisitorID : %@" , VisitorID);
NSLog(@"ProfileID : %@" , ProfileID);
NSLog(@"CompanyID : %@" , CompanyID);
NSLog(@"VisitorName : %@" , VisitorName);
NSLog(@"OperatorName : %@" , OperatorName);
NSLog(@"countryCode: %@" , isocode); …
Run Code Online (Sandbox Code Playgroud) 根据我的理解,C专家Objective-C是一种动态绑定语言,不允许重载类中的任何方法.
但是,如果我编写两个具有相同名称但不同数量的参数列表的方法,有一件事让我恼火:
// Which is not allowed in objective-c
-(void)updateValue:(int)intVal{
}
-(void)updateValue:(float)floatVal{
}
Run Code Online (Sandbox Code Playgroud)
但Objective-C允许的第二种情况是:
// Allowed in Objective-C
-(void)updateValue:(int)intVal{
}
-(void)updateValue:(float)floatVal :(int)intVal{
}
Run Code Online (Sandbox Code Playgroud)
虽然两种情况都是方法重载.
现在我的问题是为什么允许第二种情况.
在第二种情况下使用两个参数的方法是否更改了方法名称?或者是其他东西 ?
请解释一下.
当用户打开应用程序时,我从服务器获取印度时间。但是如果用户从其他国家/地区打开我的应用程序,我必须显示基于该国家/地区的时间。我该如何解决这个问题?
ios ×12
objective-c ×10
firebase ×2
afnetworking ×1
architecture ×1
arrays ×1
date ×1
dictionary ×1
iphone ×1
nsdictionary ×1
nslog ×1
nstimezone ×1
overloading ×1
swift ×1
uiimage ×1
xcode ×1