- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下代码,在应用程序终止时可以完美运行。
-(void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region{
UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"TEST NOTIFICATION";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
但是当我执行以下操作时:
-(void) createTestNotification {
UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = @"TEST";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
-(void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region{
[self createTestNotification];
}
它不起作用?我只是将我的代码移到外面没有别的吗?我知道当 didEnterRegion 被调用时,应用程序只有 5 秒,但调用此方法不会花费这个时间?
更新 1:
我刚发现地区 didEnterRegion
返回的是我开始监控的那个,而不是属于应用刚刚看到的beacon的那个。我打算使用这个区域获取我的自定义消息取决于该地区的major&minor。
但在我的情况下这是不可能的,所以我在 didEnterRegion
时开始测距接到电话,然后在didRangeBeacons
它返回 beacons 数组我从 localDataBase "depend on Major&minor" 得到了属于这个 beacon 的文本消息
这是我的代码: 此代码在应用程序后台运行时有效并收到通知,但当应用程序关闭时永远不会收到通知?
-(void)beaconManager:(id)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{
[self handelBeaconsNotification:beacons];
}
-(NSString *) getBeaconFromLocalData:(NSNumber *)regionMajor andRegionMin:(NSNumber *)regionMinor{
PFQuery *query = [PFQuery queryWithClassName:@"Beacons"];
NSArray *allRegions_id = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:1], nil];
[query whereKey:@"region_id" containedIn:allRegions_id];
NSLog(@"%@",regionMajor);
NSLog(@"%@",regionMinor);
[query whereKey:@"major" equalTo:regionMajor];
[query whereKey:@"minor" equalTo:regionMinor];
[query fromLocalDatastore];
NSArray *data = [query findObjects];
return [[data objectAtIndex:0] valueForKey:@"enter_message"];
}
-(void) handelBeaconsNotification:(NSArray *)beaconsArray{
for (int i = 0 ; i<beaconsArray.count; i++) {
NSString *currentBeaconKey = [NSString stringWithFormat:@"%@-%@",[beaconsArray[i] major],[beaconsArray[i] minor]];
if ([beaconsDictionary valueForKey:currentBeaconKey] == nil) {
NSMutableDictionary *dateDic = [[NSMutableDictionary alloc] init];
[dateDic setValue:[NSDate date] forKey:@"StartVisit"];
[dateDic setValue:nil forKey:@"EndVisit"];
[beaconsDictionary setValue:dateDic forKey:currentBeaconKey];
UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = [self getBeaconFromLocalData:[beaconsArray[i] major] andRegionMin:[beaconsArray[i] minor]];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2];
notification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
}
更新 2:我只是将 Log 添加到 didEnterRegion
和 didRangeBeacons
发现只有来自 didEnterRegion
的 NSLog然后应用程序看起来像它崩溃 和来自 didRangeBeacons
的日志没有出现
Oct 11 00:27:25 Moe-Amleh-s-iPhone kernel[0] <Notice>: xpcproxy[220] Container: /private/var/mobile/Containers/Data/Application/76CE6FC9-46AA-4C5B-9F8C-F31C1F38CAD2 (sandbox)
Oct 11 00:27:26 Moe-Amleh-s-iPhone Swipt[220] <Warning>: 111111111111111111111111
Oct 11 00:27:26 Moe-Amleh-s-iPhone locationd[70] <Notice>: Location icon should now be in state 'Active'
Oct 11 00:27:27 Moe-Amleh-s-iPhone SpringBoard[48] <Warning>: HW kbd: Failed to set (null) as keyboard focus
Oct 11 00:27:27 Moe-Amleh-s-iPhone com.apple.xpc.launchd[1] (UIKitApplication:com.swiptrewards.Swipt[0x8b1f][220]) <Notice>: Service exited due to signal: Abort trap: 6
Oct 11 00:27:27 Moe-Amleh-s-iPhone SpringBoard[48] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Notice>: platform_thread_get_unique_id matched 6383
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Notice>: Formulating report for corpse[220] Swipt
Oct 11 00:27:27 Moe-Amleh-s-iPhone assertiond[65] <Error>: assertion failed: 13A452: assertiond + 60449 [BDEA3ABF-EF9E-34B9-A166-8AE775484A67]: 0x3
Oct 11 00:27:27 Moe-Amleh-s-iPhone Unknown[65] <Error>:
Oct 11 00:27:27 Moe-Amleh-s-iPhone SpringBoard[48] <Warning>: Application 'UIKitApplication:com.swiptrewards.Swipt[0x8b1f]' crashed.
Oct 11 00:27:27 Moe-Amleh-s-iPhone UserEventAgent[23] <Warning>: 13250595064: id=com.swiptrewards.Swipt pid=220, state=0
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Warning>: report not saved because the limit of 25 for 109_Swipt logs has been reached.
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Notice: This report is abbreviated for syslog inclusion because it could not be saved to disk.
Symbolication may be possible by manually cleaning up and including the Binary Image section of a full report from this same device -- good luck!
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Process: Swipt [220]
Path: /private/var/mobile/Containers/Bundle/Application/0E547BB5-F423-48DC-B013-B549C0AE6A0E/Swipt.app/Swipt
OS Version: iOS 9.0.2 (13A452)
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Global Trace Buffer (reverse chronological seconds):
0.484432 CFNetwork 0x0000000025682aa1 TCP Conn 0x15ec9800 SSL Handshake DONE
0.586995 CFNetwork 0x0000000025682aa1 TCP Conn 0x15eb5080 SSL Handshake DONE
0.666939 CFNetwork 0x0000000025682aa1 TCP Conn 0x15eb6980 SSL Handshake DONE
0.742367 CFNetwork 0x00000000256829db TCP Conn 0x15ec9800 starting SSL negotiation
0.742681 CFNetwork 0x00000000257024cd TCP Conn 0x15ec9800 complete. fd: 13, err: 0
0.742994 CFNetwork 0x00000000257035cf TCP Conn 0x15ec9800 event 1. err: 0
0.939516 CFNetwork 0x000000002570364d TCP Conn 0x15ec9800 started
0.983614 CFNetwork 0x00000000256829db TCP Conn 0x15eb5080 starting SSL negotiation
0.983989 CFNetwork 0x00000000257024cd TCP Conn 0x15eb5080 complete. fd: 6, err: 0
0.984285 CFNetwork 0x00000000257035cf TCP Conn 0x15eb5080 event 1. err: 0
1.050325 CFNetwork 0x00000000256829db TCP Conn 0x15eb6980 starting SSL negotiation
1.052768 CFNetwork 0x00000000257024cd TCP Conn 0x15eb6980 complete. fd: 5, err: 0
1.053148 CFNetwork 0x00000000257035cf TCP Conn 0x15eb6980 event 1. err: 0
1.282007 CFNetwork 0x000000002570364d TCP Conn 0x15eb6980 started
1.282007 CFNetwork 0x000000002570364d TCP Conn 0x15eb5080 started
1.294984 CFNetwork 0x00000000257442df Creating default cookie storage with default identifier
1.294984 CFNetwork 0x00000000257442bb Faulting in CFHTTPCookieStorage singleton
1.294984 CFNetwork 0x000000002578673b Faulting in NSHTTPCookieStorage singleton
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3800cd24 0x37ff8000 + 85284
1 libsystem_pthread.dylib 0x380acb5a 0x380a9000 + 15194
2 libsystem_c.dylib 0x37fa4f50 0x37f5a000 + 307024
3 Swipt 0x003860a6 0xf0000 + 2711718
4 CoreFoundation 0x25e5fba8 0x25d6a000 + 1006504
5 libobjc.A.dylib 0x37813086 0x3780c000 + 28806
6 libc++abi.dylib 0x36ff7e16 0x36fe1000 + 93718
7 libc++abi.dylib 0x36ff78f6 0x36fe1000 + 92406
8 libobjc.A.dylib 0x37812f46 0x3780c000 + 28486
9 CoreFoundation 0x25d7326e 0x25d6a000 + 37486
10 CoreFoundation 0x25d72fdc 0x25d6a000 + 36828
11 GraphicsServices 0x2f017af8 0x2f00e000 + 39672
12 UIKit 0x29fd817c 0x29f5f000 + 495996
13 Swipt 0x00116ab0 0xf0000 + 158384
14 libdyld.dylib 0x37f3d872 0x37f3b000 + 10354
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 1:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 2 name: Dispatch queue: com.apple.libdispatch-manager
Thread 2:
0 libsystem_kernel.dylib 0x3800e3c0 0x37ff8000 + 91072
1 libdispatch.dylib 0x37f249a6 0x37f14000 + 68006
2 libdispatch.dylib 0x37f16b2e 0x37f14000 + 11054
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 3:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 4:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 5:
0 libsystem_kernel.dylib 0x37ff9130 0x37ff8000 + 4400
1 libsystem_kernel.dylib 0x37ff8f30 0x37ff8000 + 3888
2 CoreFoundation 0x25e224ec 0x25d6a000 + 754924
3 CoreFoundation 0x25e20872 0x25d6a000 + 747634
4 CoreFoundation 0x25d731e8 0x25d6a000 + 37352
5 CoreFoundation 0x25d72fdc 0x25d6a000 + 36828
6 Foundation 0x26b63d7c 0x26b58000 + 48508
7 Swipt 0x0032ef3e 0xf0000 + 2355006
8 Foundation 0x26c347fc 0x26b58000 + 903164
9 libsystem_pthread.dylib 0x380abc92 0x380a9000 + 11410
10 libsystem_pthread.dylib 0x380abc06 0x380a9000 + 11270
11 libsystem_pthread.dylib 0x380a9a24 0x380a9000 + 2596
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 6 name: Dispatch queue: NSOperationQueue 0x15ea11c0 :: NSOperation 0x15e933c0 (QOS: USER_INITIATED)
Thread 6:
0 libsystem_kernel.dylib 0x37ff9130 0x37ff8000 + 4400
1 libsystem_kernel.dylib 0x37ff8f30 0x37ff8000 + 3888
2 CoreFoundation 0x25e224ec 0x25d6a000 + 754924
3 CoreFoundation 0x25e20872 0x25d6a000 + 747634
4 CoreFoundation 0x25d731e8 0x25d6a000 + 37352
5 CoreFoundation 0x25db3faa 0x25d6a000 + 303018
6 Foundation 0x26c1ecc4 0x26b58000 + 814276
7 libdispatch.dylib 0x37f1f04e 0x37f14000 + 45134
8 libdispatch.dylib 0x37f1802e 0x37f14000 + 16430
9 libdispatch.dylib 0x37f203dc 0x37f14000 + 50140
10 libdispatch.dylib 0x37f2024a 0x37f14000 + 49738
11 libsystem_pthread.dylib 0x380a9e28 0x380a9000 + 3624
12 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 7:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 8 name: com.apple.NSURLConnectionLoader
Thread 8:
0 libsystem_kernel.dylib 0x37ff9130 0x37ff8000 + 4400
1 libsystem_kernel.dylib 0x37ff8f30 0x37ff8000 + 3888
2 CoreFoundation 0x25e224ec 0x25d6a000 + 754924
3 CoreFoundation 0x25e20872 0x25d6a000 + 747634
4 CoreFoundation 0x25d731e8 0x25d6a000 + 37352
5 CoreFoundation 0x25d72fdc 0x25d6a000 + 36828
6 CFNetwork 0x256e40ae 0x2565c000 + 557230
7 Foundation 0x26c347fc 0x26b58000 + 903164
8 libsystem_pthread.dylib 0x380abc92 0x380a9000 + 11410
9 libsystem_pthread.dylib 0x380abc06 0x380a9000 + 11270
10 libsystem_pthread.dylib 0x380a9a24 0x380a9000 + 2596
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 9:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 10:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 11:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 12:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 13:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 14:
0 libsystem_kernel.dylib 0x3800d92c 0x37ff8000 + 88364
1 libsystem_pthread.dylib 0x380a9e34 0x380a9000 + 3636
2 libsystem_pthread.dylib 0x380a9a18 0x380a9000 + 2584
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 15 name: com.apple.CFSocket.private
Thread 15:
0 libsystem_kernel.dylib 0x3800cfb4 0x37ff8000 + 85940
1 CoreFoundation 0x25e27990 0x25d6a000 + 776592
2 libsystem_pthread.dylib 0x380abc92 0x380a9000 + 11410
3 libsystem_pthread.dylib 0x380abc06 0x380a9000 + 11270
4 libsystem_pthread.dylib 0x380a9a24 0x380a9000 + 2596
Oct 11 00:27:27 Moe-Amleh-s-iPhone ReportCrash[221] <Error>: Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000004 r1: 0x00000000 r2: 0x15eb25d0 r3: 0x00000000
r4: 0x00000000 r5: 0x00000000 r6: 0x15e81c60 r7: 0x4072cfb4
r8: 0x15eb25d0 r9: 0x3ae01900 r10: 0x00000000 r11: 0x00000020
ip: 0x0000005d sp: 0x40724bec lr: 0x25e27991 pc: 0x3800cfb4
最佳答案
嗯,我认为您正在使用空区域变量,因此请确保您正确发送它并且不要将空变量用于 startRanging 方法。
当您的应用关闭时,所有变量都将终止,因此请确保您传递的变量不为空。
关于ios - Local Notification 什么时候EnterRegion?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016073/
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!