小编Ida*_*she的帖子

didReceiveRemoteNotification:当app在后台并且没有连接到Xcode时,没有调用fetchCompletionHandler

我有一个非常奇怪的问题,我实施了:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler
Run Code Online (Sandbox Code Playgroud)

用于静音远程推送通知.当应用程序处于后台并连接到Xcode时,它非常适用.当我拔下任何iOS设备并运行应用程序时,请移至后台并发送远程通知,didReceiveRemoteNotification:fetchCompletionHandler而不是被调用.

我的代码如下:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    NSInteger pushCode = [userInfo[@"pushCode"] integerValue];
    NSLog(@"Silent Push Code Notification: %i", pushCode);
    NSDictionary *aps = userInfo[@"aps"];
    NSString *alertMessage = aps[@"alert"];

    if (pushCode == kPushCodeShowText) {
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        localNotif.fireDate = [NSDate date];
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
        localNotif.alertBody = alertMessage;
        localNotif.alertAction = @"OK";
        localNotif.soundName = @"sonar.aiff";
        // localNotif.applicationIconBadgeNumber = 0;
        localNotif.userInfo = nil;
        [[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];

        UILocalNotification *clearNotification …
Run Code Online (Sandbox Code Playgroud)

debugging background objective-c apple-push-notifications ios

43
推荐指数
5
解决办法
4万
查看次数

检索iOS中的所有联系人电话号码

到目前为止,我看到了获取多个电话号码的方法,如果我显示一个选择器,那么用户可以选择人员,然后获取电话号码.我想要的是检索所有联系人的号码. 它甚至可能吗?

objective-c contacts ios

12
推荐指数
2
解决办法
3万
查看次数

区域监控当前位置在退出时不通知

我正在尝试测试区域监控,因为我正在获得这样的当前位置:

- (void)startLocationTracking
{
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];

    // Start location manager
    if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
        locationManager = [LocationTracker sharedLocationManager];
        locationManager.delegate = self;
        [locationManager startMonitoringSignificantLocationChanges];
    }
}
Run Code Online (Sandbox Code Playgroud)

并跟踪区域监控的第一个位置,如下所示:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:manager.location.coordinate radius:300 identifier:@"first location initializer"];

        NSLog(@"0: %@", manager.location);
        NSLog(@"1: %@", region);

        [manager startMonitoringForRegion:region];
        NSLog(@"[locationManager startMonitoringForRegion:%@];", region);
    });
}
Run Code Online (Sandbox Code Playgroud)

然后在当前区域的每个出口处,我正在监视新位置,如下所示:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
    NSLog(@"%s, %@", __PRETTY_FUNCTION__, region);
} …
Run Code Online (Sandbox Code Playgroud)

objective-c core-location cllocationmanager ios clregion

12
推荐指数
1
解决办法
4420
查看次数

在第一个视图控制器中添加"addObserver"(NSNotificationCenter),在第二个视图中处理

我看到了一些关于在同一个类中添加观察者和句柄的例子,但我想知道的是,是否可以在第一个视图控制器中添加观察者并在第二个视图控制器中处理它?

我希望不断从第一个视图控制器发送距离并在第二个控制器中处理它.第二个视图控制器添加为子视图:addSubview,addChildViewController.

它就像android中的广播一样.

objective-c observers nsnotification nsnotificationcenter ios

7
推荐指数
1
解决办法
2万
查看次数

点击"myLocation"按钮时触发(适用于iOS的Google Maps SDK)

点击"myLocation"按钮时,我想做一些事情.到目前为止,我UIButton自己:

UIButton *btnMyLoc = (UIButton*)[self.googleMapView subviews].lastObject;
Run Code Online (Sandbox Code Playgroud)

但这还不够.有任何想法吗?

ios google-maps-sdk-ios

5
推荐指数
1
解决办法
5663
查看次数

核心数据executeFetchRequest失败,带有exc_bad_access

根据我的理解,这是一个内存问题,特别是因为我用不同的定时器从几个地方多次调用该方法.

抛出异常的代码如下:

- (NSMutableArray*)getAllTraps
{
    @synchronized(self)
    {
        self.fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Trap"];
        NSError *error = nil;
        NSArray *results = [self.managedObjectContext executeFetchRequest:self.fetchRequest error:&error];

        if (!results)
        {
            NSLog(@"Error fetching traps: %@", error.localizedDescription);
            NSLog(@"Reason: %@", error.localizedFailureReason);
            NSLog(@"Suggestion: %@", error.localizedRecoverySuggestion);
            abort();
        }


        if (error != nil)
        {
            // Handle error
            NSLog(@"Error getting all traps");
        }
        else
        {
            // Handle success
            NSLog(@"Success getting all traps");
        }


        NSMutableArray *arrayOfAllTraps = [[NSMutableArray alloc] init];
        for (int i = 0; i < results.count; i++)
        {
            Trap *singleTrap = …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c nsfetchrequest ios

5
推荐指数
1
解决办法
3051
查看次数

' - [__ NSDictionaryI length]:无法识别的选择器发送到实例' - 试图找出原因

我有一个UITableView自定义UILabel标题和另一个副标题,以便将文本对齐.

我的数据来自Web服务,这是我在分析和存储NSArrayNSDictionary.一些标题或副标题可以是零/空文本.为此,我把它放在try/catch中.

我的桌子中的一条线让我的应用程序粉碎,我无法弄清楚原因.

我认为其中一个(标题/副标题)返回,NSDictionary 但我为我的对象做了一个日志打印,对于我来说[UILabel text],似乎一切都好.

异常和堆栈跟踪:

2014-04-29 10:47:55.985 Cellular Radar[3226:60b] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:55.993 Cellular Radar[3226:60b] -[Home tableView:willDisplayCell:forRowAtIndexPath:], exception.reason: -[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:55.999 Cellular Radar[3226:60b] -[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:56.006 Cellular Radar[3226:60b] CRASH:
-[__NSDictionaryI length]: unrecognized selector sent to instance 0x16d007f0
2014-04-29 10:47:56.062 Cellular Radar[3226:60b] Stack Trace:
(
    0   CoreFoundation                      0x30e02feb …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

5
推荐指数
1
解决办法
9975
查看次数

通过重试将NSOperation子类化为互联网操作

我在后台线程中将NSOperation子类化为http post.那些特定的http帖子不需要返回任何值.

我想要做的是当我出现错误或超时时我希望它在增加延迟后发送(斐波那契).

到目前为止我已经这样做了:

NSInternetOperation.h:

#import <Foundation/Foundation.h>

@interface NSInternetOperation : NSOperation
@property (nonatomic) BOOL executing;
@property (nonatomic) BOOL finished;
@property (nonatomic) BOOL completed;
@property (nonatomic) BOOL cancelled;
- (id)initWebServiceName:(NSString*)webServiceName andPerameters:(NSString*)parameters;
- (void)start;
@end
Run Code Online (Sandbox Code Playgroud)

NSInternetOperation.m:

#import "NSInternetOperation.h"

static NSString * const kFinishedKey = @"isFinished";
static NSString * const kExecutingKey = @"isExecuting";

@interface NSInternetOperation ()
@property (strong, nonatomic) NSString *serviceName;
@property (strong, nonatomic) NSString *params;
- (void)completeOperation;
@end

@implementation NSInternetOperation

- (id)initWebServiceName:(NSString*)webServiceName andPerameters:(NSString*)parameters
{
    self = [super init];
    if (self) {
        _serviceName …
Run Code Online (Sandbox Code Playgroud)

multithreading objective-c nsoperation ios

4
推荐指数
1
解决办法
2777
查看次数

UIActivityViewController联系人共享?

我正在尝试考虑一种方法来使用UIActivityViewController(或使用SMS)从一个设备与另一个设备共享联系.

到目前为止,我一直在寻找,我不知道如何使用我的应用程序在设备之间共享联系人.

有任何想法吗?

ios uiactivityviewcontroller

3
推荐指数
1
解决办法
1118
查看次数

从哪里开始,在Faye for iOS中实施长轮询

我使用内置的MZFayeClient(https://github.com/m1entus/MZFayeClient)WebSocket.我需要实现长轮询技术.怎么做?从哪儿开始?没有关于如何操作的信息(或足够的信息),或者是否存在具有长轮询的Faye库.

long-polling ios faye

3
推荐指数
1
解决办法
464
查看次数