我试图通过蓝牙4.0 LE将一个.png图像文件从一个iOS设备发送到另一个.
我能够像字符串一样简单的数据,但无法成功发送和利用图像文件.
在外围设备中,我从这开始
pictureBeforeData = [UIImage imageNamed:@"myImage.png"];
NSData *myData = UIImagePNGRepresentation(pictureBeforeData);
Run Code Online (Sandbox Code Playgroud)
然后我创造myData
了一个特征的价值.
_myCharacteristic =
[[CBMutableCharacteristic alloc] initWithType:_myCharacteristicUUID
properties:CBCharacteristicPropertyRead
value:myData
permissions:CBAttributePermissionsReadable];
Run Code Online (Sandbox Code Playgroud)
在中央设备中,我会在更新特征值时使用此功能
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:_myCharacteristicUUID]]) {
NSLog(@"PICTURE CHARACTERISTIC FOUND"); // This successfully gets logged
NSData *dataFromCharacteristic = [[NSData alloc] initWithData:characteristic.value];
UIImage *imageFromData = [[UIImage alloc]initWithData:dataFromCharacteristic];
// This correctly logs the size of my image
NSLog(@"SIZE: %f, %f", imageFromData.size.height, imageFromData.size.width);
// This causes the imageView to turn completely black
_sentPictureImageView.image …
Run Code Online (Sandbox Code Playgroud) 我已经构建了一个类似于Snapchat的消息传递应用程序 - 一个用户可以发送另一个用户图片.我正在尝试向应用添加推送通知,以便当从UserA向UserB发送消息时,UserB会收到"来自UserA的新消息"的推送通知.
我一直在研究这几个小时,我觉得我很亲密.
我正在尝试使用Parse发送推送通知.我希望它的工作方式如下:当UserA向UserB发送消息时,还会向UserB发送一条推送通知,其中显示"来自UserA的新消息".我成功地使用Parse网站向使用该应用程序的设备发送推送通知,但是无法在应用程序内(当用户发送消息时)向接收用户的设备成功发送推送通知.
推送通知显然是成功发送的,因为我的Parse帐户显示了我发送的消息.但是,没有消息实际到达目标设备,推送通知列表显示每个推送通知的0个订阅者.
我可以点击其中一个来查看详细信息.
此外,我正在使用分发/生产供应配置文件和证书.
这是我在UserA向UserB发送消息后发送推送通知的代码 - message
对象是已上传到Parse的消息,messageRecipients是消息发送到的用户:
// Send Push Notification to recipients
NSArray *messageRecipients = [message objectForKey:@"recipientIds"];
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"owner" containedIn:messageRecipients];
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery];
[push setMessage:[NSString stringWithFormat: @"New Message from %@!", [PFUser currentUser].username]];
[push sendPushInBackground];
Run Code Online (Sandbox Code Playgroud)
这是我的AppDelegate.m相关方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse setApplicationId:@"[This is where my app Id is]"
clientKey:@"[This is where client Id is]"];
[self customizeUserInterface];
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
return YES;
} …
Run Code Online (Sandbox Code Playgroud) 我有一个使用蓝牙4.0 LE的应用程序.该应用程序允许设备充当中央和外围设备.
我希望应用程序在后台运行.我已经在info.plist中包含了带有"bluetooth-central"和"bluetooth-peripheral"的UIBackgroundModes.
我正在两个启用了蓝牙4.0 LE的设备上运行该应用程序.
当两个设备都在前台运行时,一切都运行良好,信息双向传递.
当一台设备在前台运行而另一台设备在后台运行时,在后台运行的设备可以扫描和通告,但无法发现在后台运行的其他设备.在前台运行的设备能够发现并连接到后台运行的设备.
通过Apple的核心蓝牙编程指南阅读后,我知道可以连接到另一台设备并以两种方式共享信息.
我可以根据要求发布更多信息.谢谢.
bluetooth background-process ios core-bluetooth bluetooth-lowenergy
我有一个NSStrings
,一个UILabel
和一个阵列UICollectionView
.
我的问题:
我想要数组的数量来确定它有多少UICollectionViewCell
.
每个都UICollectionViewCell
包含一个按钮.单击后,我希望此按钮使数组中与UICollectionViewCell
数字对应的数据显示在标签中.
例如,如果用户单击第13个UICollectionViewCell
按钮,则NSString
数组中的第13个将成为UILabel
文本.
我做了什么:
我已经UICollectionViewCell
为我用于所有UICollectionViewCell
s 的nib文件创建了自己的子类,并将按钮连接到.h文件作为IBAction
.我还导入了MainViewController.h
包含存储NSString
s 的数组属性的那个.
当我在UICollectionViewCell
动作中编辑代码时,我无法访问数组属性.按钮确实有效 - 我在IBAction
方法中放置了一个NSLog ,它确实有效.
我在SO上搜索了数十个其他答案,但没有人回答我的具体问题.如果需要,我可以使用我的代码示例更新此内容.