I have a code to know which beacon is the closest, but I have a problem when a beacon's accuracy is -1.00000, the the app takes the second one.
So there is a bucle that seek for the closest beacon looking for others and comparing the one closest with the others found around. Then when I know which is the closest one I show it's view to the user, but when other beacon is closer to the ipad the view is close and the view is shown.
I'm using iOS 7.1 and 7.0.4 on 2 iPads, first is iPad3 and the second one is an iPad Mini Retina.
Here you have the code:
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
- (void)initRegion {
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:#"00000000-0000-0000-0000-000000000002"];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:#"com.devfright.myRegion"];
[self.locationManager startMonitoringForRegion:self.beaconRegion];
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(#"Beacon Found");
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
NSLog(#"Left Region");
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
CLBeacon *beacon = [[CLBeacon alloc] init];
CLBeacon *closestBeacon = [[CLBeacon alloc] init];
closestBeacon = [beacons lastObject];
//Search for the closest and show the view
for (int i=0; i<beacons.count; i++) {
beacon = beacons[i];
if (beacon.accuracy < closestBeacon.accuracy && beacon.accuracy != -1.000000 && beacon.minor != closestBeacon.minor && beacon.proximity != CLProximityFar) {
closestBeacon = beacons[i];
//NSString *closeAccuracy = closestBeacon.minor.stringValue;
}
NSLog(#"\nActualBeacon:%#\nAccuracy:%f", beacon.minor.stringValue,beacon.accuracy);
NSLog(#"\nCloserBeacon: %#\nAccuracy:%f", closestBeacon.minor.stringValue, closestBeacon.accuracy);
}
NSLog(#"\nClosestBeacon: %#", closestBeacon.minor.stringValue);
if (viewShown == NO) {
if ([closestBeacon.minor.stringValue isEqual: #"1"]) {
actualSection = 1;
[self immediateDetection];
}else if ([closestBeacon.minor.stringValue isEqual: #"2"]){
actualSection = 2;
[self immediateDetection];
}else if ([closestBeacon.minor.stringValue isEqual: #"3"]){
actualSection = 3;
[self immediateDetection];
}else if ([closestBeacon.minor.stringValue isEqual: #"4"]){
actualSection = 4;
[self immediateDetection];
}else if ([closestBeacon.minor.stringValue isEqual: #"5"]){
actualSection = 5;
[self immediateDetection];
}else if ([closestBeacon.minor.stringValue isEqual: #"6"]){
actualSection = 6;
[self immediateDetection];
NSLog(#"6");
}else if ([closestBeacon.minor.stringValue isEqual: #"7"]){
actualSection = 7;
[self immediateDetection];
NSLog(#"7");
}else if ([closestBeacon.minor.stringValue isEqual: #"8"]){
actualSection = 8;
[self immediateDetection];
NSLog(#"8");
}else if ([closestBeacon.minor.stringValue isEqual: #"9"]){
actualSection = 9;
[self immediateDetection];
NSLog(#"9");
}else if ([closestBeacon.minor.stringValue isEqual: #"10"]){
actualSection = 10;
[self immediateDetection];
NSLog(#"10");
}else if ([closestBeacon.minor.stringValue isEqual: #"11"]){
actualSection = 11;
[self immediateDetection];
NSLog(#"11");
}else if ([closestBeacon.minor.stringValue isEqual: #"30"]){
actualSection = 30;
[self immediateDetection];
}
} else if (viewShown == YES) {
if (closestBeacon.minor.integerValue != actualSection) {
//Alarm: Beacon 11
// if (closestBeacon.minor.integerValue != 11 || closestBeacon.minor.integerValue != 10) {
[self dismissViewControllerAnimated:NO completion:nil];
//actualSection = 0;
viewShown = NO;
// }
}
}
}
- (void)immediateDetection
{
viewShown = YES;
if (self.presentedViewController)
{
return;
}
if (actualSection == 1) {
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 1;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 2){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 2;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 3){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 3;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 4){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 4;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 5){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 5;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 6){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 6;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 7){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 7;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 8){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 8;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 9){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 9;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}else if (actualSection == 10){
ThiefAlarmViewController *thiefAlarmView = [[ThiefAlarmViewController alloc] init];
[self presentViewController:thiefAlarmView animated:NO completion:nil];
}else if (actualSection == 11){
ThiefAlarmViewController *thiefAlarmView = [[ThiefAlarmViewController alloc] init];
[self presentViewController:thiefAlarmView animated:NO completion:nil];
}else if (actualSection == 30){
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = 30;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}
}
When I know the closest iBeacon I show it's view, but when it's accuracy is -1.00000 and compare to others the app takes the second one cause the first has it's accuracy = -1.00000 .
Hope anyone can help me cause I don't know what to do, maybe this is an iBeacon problem, but I think there is a solution for this issue.
Thanks.
locationManager:didRangeBeacons:inRegion: will return you a list of beacons in proximity order. That is, the first beacon in the list will be the nearest to you.
However, there is one exception to this rule: if any beacons have a proximity of Unknown, then they will be at the top of the list (because their accuracy is -1). To account for this, simply filter out any Unknown beacons, and then pick the first in the list:
beacons = [beacons filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"proximity != %d", CLProximityUnknown]];
CLBeacon *nearestBeacon = [beacons firstObject];
First of all:
Replace your long else/if of locationManager:didRangeBeacons:inRegion: with:
if (([closestBeacon.minor intValue] > 0 && [closestBeacon.minor intValue] <= 11) || [closestBeacon.minor intValue] == 30)
{
actualSection = [closestBeacon.minor intValue];
[self immediateDetection];
}
Replace your long else/if in immediateDetection with:
if ((actualSection > 0 && actualSection < 10 || actualSection == 30)
{
SectionViewController *sectionView = [[SectionViewController alloc] init];
sectionView.section = actualSection;
[self presentViewController:sectionView animated:NO completion:nil];
sectionView.lbl_name.text = self.lbl_name.text;
}
else if (actualSection == 10 || actualSection == 11)
{
ThiefAlarmViewController *thiefAlarmView = [[ThiefAlarmViewController alloc] init];
[self presentViewController:thiefAlarmView animated:NO completion:nil];
}
else
{
}
That should save you a lot of code.
For your issue, you could to this:
NSPredicate *predicateIrrelevantBeacons = [NSPredicate predicateWithFormat:#"(self.accuracy != -1) AND ((self.proximity != %d) OR (self.proximity != %d))", CLProximityFar,CLProximityUnknown];
NSArray *relevantsBeacons = [beacons filteredArrayUsingPredicate: predicateIrrelevantBeacons];
NSPredicate *predicateMin = [NSPredicate predicateWithFormat:#"self.accuracy == %#.#min.accuracy", relevantsBeacons];
CLBeacon *closestBeacon = nil;
NSArray *closestArray = [[relevantsBeacons filteredArrayUsingPredicate:predicateMin];
if ([closestArray count] > 0)
closestBeacon = [closestArray objectAtIndex:0];
if (closestBeacon)
{ //Do your thing }
else
{//No relevant close beacon}
In addition to filtering out proximity values of -1, you also have to take into account cases where certain iBeacons periodically do not appear in a callback to didRangeBeacons: inRegion. This can happen due to radio interference, especially for battery powered beacons that do not transmit advertisements very frequently.
To solve this, you need to keep your own list of recently seen beacons, and track any beacons that have been seen in the last few seconds. If one of the beacons has a proximity of -1, you can either not put it in the list, or re-use the last known non -1 proximity value if it does not exist.
Another consideration that you need to take into account is that the proximity value will bounce around quite a bit. You may need to add some hysteresis logic to your algorithm so which beacon is the closest doesn't bounce back and forth every second. The specifics of how you want to do this depend on your use case.
Related
Has anyone noticed with the changes added to UISwitch in Beta 4, that if you set a switches tag, for some reason it doesn't respect it? I add a switch programmatically to the accessory view of a TableView cell and once the cell is selected I access the switch to get it's tag to know which switch it was and the state that was changed.
Here are the code examples:
if (_showSwitch) {
if (cell.accessoryView == nil) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switchview = [[UISwitch alloc]initWithFrame:CGRectZero];
switchview.tag = indexPath.row;
cell.accessoryView = switchview;
[switchview addTarget:self action:#selector(switchChanged:)
forControlEvents:UIControlEventValueChanged];
cell.backgroundColor = UIColor.systemGray2Color;
}
NSArray *strArray = [_tableDataSource[indexPath.row] componentsSeparatedByString:#"/"];
_row = indexPath.row;
_cellLabel = strArray[0];
cell.textLabel.text = _cellLabel;
_cellArray = [_cellArray arrayByAddingObject:(NSString *)_cellLabel];
if (_level >= 1) {
_deviceID = strArray[1];
_deviceArray = [_deviceArray arrayByAddingObject:_deviceID];
_lowcaseDeviceID = _deviceID = _deviceID.lowercaseString;
dictLookup = _statusDict[_lowcaseDeviceID];
if (_row >= 1) {
mycmdString = [mycmdString stringByAppendingString:#","];
}
mycmdString = [mycmdString stringByAppendingString:_deviceID];
UISwitch *switchView = (UISwitch *)cell.accessoryView;
[switchView setOn:NO animated:NO];
if ([dictLookup isEqualToString:#"ON"]) {
cell.textLabel.textColor = UIColor.systemGreenColor;
[switchView setOn:YES animated:YES];
}
_callForStatus = TRUE;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
- (IBAction)ControlView:(UISwitch *)sender {
ControlViewController *flController = [[ControlViewController alloc]
initWithNibName:#"ControlViewController" bundle:nil];
(flController.navigationItem).title = [NSString stringWithFormat:#"%# - %#", _deviceName, _device];
_level = _level += 1;
flController.deviceID = _device;
flController.deviceName = _deviceName;
flController.deviceState = #"OFF";
if ((sender.isOn) == YES) {
flController.deviceState = #"ON";
}
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
[self presentViewController:flController animated:YES completion:nil];
});
}
- (void)switchChanged:(UISwitch *)sender {
bool mode;
UISwitch *switchControl = sender;
if (switchControl.isOn == YES) {
[switchControl setOn:YES animated:YES];
mode = TRUE;
[General playSound:#"Button Up.mp3"];
} else {
[switchControl setOn:NO animated:NO];
mode = FALSE;
[General playSound:#"Button Down.mp3"];
}
sender.highlighted = YES;
_callForStatus = TRUE;
[self executeSwitchAtRow:switchControl.tag forMode:mode];
// if (_level >= 1) [self startStepperTimer];
}
- (void)executeSwitchAtRow:(NSInteger)row forMode:(BOOL)onoff {
NSString *mode = #"OFF";
if (onoff) {
mode = #"ON";
}
NSString *device = _deviceArray[row];
Debug_1(#"Send Switch Change for device %# %#",device,mode);
NSString *execCommand = [NSString stringWithFormat:#"device %# %#", mode, device];
[[NSNotificationCenter defaultCenter] postNotificationName:#"sendMessageFromExternal" object:self
userInfo:#{ #"cmd": execCommand }];
if (_level >= 1) [self startStepperTimer];
}
...
I have a complex tableView, which's cell have many contents.
And when I reloadData my tableView, the cpu usage raise up quickly, even to 180%!
So, in real device, 5c or 5s, the app will crash, I think is because the cpu usage the app crash.
So, is there a method to limit the cpu usage or let app do not crash?
Addition-1
I don't think the tableView delegate methods is help for the question ,but I will also put part of them:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:exp_TableIdentifier];
if (cell == nil) {
cell = [[LMLAgricultureTechCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:exp_TableIdentifier];
}
((LMLAgricultureTechCell *)cell).model = self.help_dataSource[indexPath.row];
((LMLAgricultureTechCell *)cell).indexPath = indexPath;
((LMLAgricultureTechCell *)cell).delegate = self;
((LMLAgricultureTechCell *)cell).photo_view.delegate = self;
// solve SDWebImage memory increase
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache clearMemory];
return cell;
}
In the LMLAgricultureTechCell.m:
- (void)setModel:(LMLAgricultureTechModel *)model{
_model = model;
_shouldOpenContentLabel = NO;
// 1.头像
_iconView.image = [UIImage imageNamed:model.lml_iconName];
[_iconView sd_setImageWithURL:[NSURL URLWithString:model.lml_iconName] placeholderImage:img_placeholder_circle_header];
[Util roundBorderView:_iconView.bounds.size.width / 2.0 border:0 color:nil view:_iconView];
// 2.名字
_nameLabel.text = model.lml_userName == nil || [model.lml_userName isEqual: #""] || [model.lml_userName isEqual:[NSNull null]] ? #"" : model.lml_userName; // 未获得用户名
// 防止单行文本Label在重新用的时候宽度计算不准的问题
[_nameLabel sizeToFit];
// 3.地址
_loacation.text = model.lml_location == nil || [model.lml_location isEqual: #""] || [model.lml_location isEqual:[NSNull null]] ? #"" : [model.lml_location componentsSeparatedByString:#"-"].lastObject; //未获得地址
// 4.时间
_time.text = model.lml_time == nil || [model.lml_time isEqual: #""] || [model.lml_time isEqual:[NSNull null]] ? #"" : model.lml_time;
// 未获取时间
[_time sizeToFit];
// 5.标题
_title.text = model.lml_title == nil || [model.lml_title isEqual: #""] || [model.lml_title isEqual:[NSNull null]] ? #"" : model.lml_title; //未获得标题
//[_title sizeToFit];
// 6.内容
_content.text = model.lml_content;
_photo_view.picPathStringsArray = model.lml_imagesArr;
// 7.如果文字高度超过60
if (model.shouldShowMoreButton) {
_allContent.sd_layout.heightIs(20);
_allContent.hidden = NO;
// 如果需要展开
if (model.isOpening) {
_content.sd_layout.maxHeightIs(MAXFLOAT);
[_allContent setTitle:NSLocalizedString(#"收起", nil) forState:UIControlStateNormal];
}else {
_content.sd_layout.maxHeightIs(maxContentLabelHeight);
[_allContent setTitle:NSLocalizedString(#"全文", nil) forState:UIControlStateNormal];
}
}else {
_allContent.sd_layout.heightIs(0);
_allContent.hidden = YES;
}
if (model.isMyPost) {
_delete.sd_layout.heightIs(20).widthIs(40);
_delete.hidden = NO;
}else {
_delete.sd_layout.heightIs(0);
_delete.hidden = YES;
}
// 8.现在判断allOrDelete back
if (_allContent.hidden == YES && _delete.hidden == YES) {
_allAndDeleteView.sd_layout.heightIs(0);
}else {
_allAndDeleteView.sd_layout.heightIs(20);
}
// 9.图片数组
CGFloat picContainerTopMargin = 0;
if (model.lml_imagesArr.count) {
picContainerTopMargin = 10;
}
_photo_view.sd_layout.topSpaceToView(_allAndDeleteView, picContainerTopMargin);
_photo_view.picPathStringsArray = model.lml_imagesArr;
_showCountlabel.text = model.lml_scanTimes;
_goodImageView.image = model.lml_isLiked ? [UIImage imageNamed:#"pre_list_thumb_selected.png"]:[UIImage imageNamed:#"pre_list_thumb"];
_goodCountlabel.text = model.lml_likeTimes;
_speakCountlabel.text = model.lml_commentTimes;
// 底部的
_bottomView = part3;
[self setupAutoHeightWithBottomView:_bottomView bottomMargin:15];
}
I have tableviews in my storyboard and it is working till Xcode 7.3, After Updating Xcode to 8, imageviews that are added in tableviewcell are not render first time until you scroll OR explicitly call reloadData. Imageviews are added from storyboard.
After scrolling
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ALContactCell *contactCell;
switch (indexPath.section)
{
case 0:
{
//Cell for group button....
contactCell = (ALContactCell *)[tableView dequeueReusableCellWithIdentifier:#"groupCell"];
//Add group button.....
UIButton *newBtn = (UIButton*)[contactCell viewWithTag:101];
[newBtn addTarget:self action:#selector(createGroup:) forControlEvents:UIControlEventTouchUpInside];
newBtn.userInteractionEnabled = YES;
}break;
case 1:
{
//Add rest of messageList
contactCell = (ALContactCell *)[tableView dequeueReusableCellWithIdentifier:#"ContactCell"];
[contactCell.mUserNameLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:USER_NAME_LABEL_SIZE]];
[contactCell.mMessageLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:MESSAGE_LABEL_SIZE]];
[contactCell.mTimeLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:TIME_LABEL_SIZE]];
[contactCell.imageNameLabel setFont:[UIFont fontWithName:[ALApplozicSettings getFontFace] size:IMAGE_NAME_LABEL_SIZE]];
contactCell.unreadCountLabel.backgroundColor = [ALApplozicSettings getUnreadCountLabelBGColor];
contactCell.unreadCountLabel.layer.cornerRadius = contactCell.unreadCountLabel.frame.size.width/2;
contactCell.unreadCountLabel.layer.masksToBounds = YES;
//contactCell.mUserImageView.hidden = NO;
contactCell.mUserImageView.layer.cornerRadius = contactCell.mUserImageView.frame.size.width/2;
contactCell.mUserImageView.layer.masksToBounds = YES;
[contactCell.onlineImageMarker setBackgroundColor:[UIColor clearColor]];
UILabel* nameIcon = (UILabel*)[contactCell viewWithTag:102];
nameIcon.textColor = [UIColor whiteColor];
ALMessage *message = (ALMessage *)self.mContactsMessageListArray[indexPath.row];
ALContactDBService *contactDBService = [[ALContactDBService alloc] init];
ALContact *alContact = [contactDBService loadContactByKey:#"userId" value: message.to];
ALChannelDBService * channelDBService =[[ALChannelDBService alloc] init];
ALChannel * alChannel = [channelDBService loadChannelByKey:message.groupId];
if([message.groupId intValue])
{
ALChannelService *channelService = [[ALChannelService alloc] init];
[channelService getChannelInformation:message.groupId orClientChannelKey:nil withCompletion:^(ALChannel *alChannel)
{
contactCell.mUserNameLabel.text = [alChannel name];
contactCell.onlineImageMarker.hidden=YES;
}];
}
else
{
contactCell.mUserNameLabel.text = [alContact getDisplayName];
}
contactCell.mMessageLabel.text = message.message;
contactCell.mMessageLabel.hidden = NO;
if ([message.type integerValue] == [FORWARD_STATUS integerValue])
contactCell.mLastMessageStatusImageView.image = [ALUtilityClass getImageFromFramworkBundle:#"mobicom_social_forward.png"];
else if ([message.type integerValue] == [REPLIED_STATUS integerValue])
contactCell.mLastMessageStatusImageView.image = [ALUtilityClass getImageFromFramworkBundle:#"mobicom_social_reply.png"];
BOOL isToday = [ALUtilityClass isToday:[NSDate dateWithTimeIntervalSince1970:[message.createdAtTime doubleValue]/1000]];
contactCell.mTimeLabel.text = [message getCreatedAtTime:isToday];
[self displayAttachmentMediaType:message andContactCell:contactCell];
// here for msg dashboard profile pic
[nameIcon setText:[ALColorUtility getAlphabetForProfileImage:[alContact getDisplayName]]];
if([message getGroupId])
{
[contactCell.onlineImageMarker setHidden:YES];
}
else if(alContact.connected && [ALApplozicSettings getVisibilityForOnlineIndicator])
{
[contactCell.onlineImageMarker setHidden:NO];
}
else
{
[contactCell.onlineImageMarker setHidden:YES];
}
if(alContact.block || alContact.blockBy)
{
[contactCell.onlineImageMarker setHidden:YES];
}
BOOL zeroContactCount = (alContact.unreadCount.intValue == 0 ? true:false);
BOOL zeroChannelCount = (alChannel.unreadCount.intValue == 0 ? true:false);
if(zeroChannelCount || zeroContactCount)
{
contactCell.unreadCountLabel.text = #"";
[contactCell.unreadCountLabel setHidden:YES];
}
if(!zeroContactCount && [alContact userId] && (message.groupId.intValue == 0 || message.groupId == NULL)){
[contactCell.unreadCountLabel setHidden:NO];
contactCell.unreadCountLabel.text=[NSString stringWithFormat:#"%i",alContact.unreadCount.intValue];
}
else if(!zeroChannelCount && [message.groupId intValue]){
[contactCell.unreadCountLabel setHidden:NO];
contactCell.unreadCountLabel.text = [NSString stringWithFormat:#"%i",alChannel.unreadCount.intValue];
}
contactCell.mUserImageView.backgroundColor = [UIColor whiteColor];
if([message.groupId intValue])
{
[contactCell.mUserImageView setImage:[ALUtilityClass getImageFromFramworkBundle:#"applozic_group_icon.png"]];
NSURL * imageUrl = [NSURL URLWithString:alChannel.channelImageURL];
if(imageUrl)
{
[contactCell.mUserImageView sd_setImageWithURL:imageUrl];
}
nameIcon.hidden = YES;
}
else if(alContact.contactImageUrl)
{
NSURL * theUrl1 = [NSURL URLWithString:alContact.contactImageUrl];
[contactCell.mUserImageView sd_setImageWithURL:theUrl1];
nameIcon.hidden = YES;
}
else
{
nameIcon.hidden = NO;
[contactCell.mUserImageView sd_setImageWithURL:[NSURL URLWithString:#""]];
contactCell.mUserImageView.backgroundColor = [ALColorUtility getColorForAlphabet:[alContact getDisplayName]];
}
}break;
default:
break;
}
return contactCell;
}
After long hit and trials it worked after updating
dispatch_async(dispatch_get_main_queue(), ^{
contactCell.mUserImageView.layer.cornerRadius = contactCell.mUserImageView.frame.size.width/2;
contactCell.mUserImageView.layer.masksToBounds = YES;
});
OR
you can use context graphics to get circular image
But still need a prior solution
*This is the whole code :)
I have been trying to fix this for an hour now, but i can still not make it.
I would be happy if someone could help me :)
Still can't make the UI_USER_INTERFACE_IDIOM code work.*
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)Collision{
if (CGRectIntersectsRect(Heli.frame, Obstacle.frame)) {
[self EndGame];
}
if (CGRectIntersectsRect(Heli.frame, Obstacle2.frame)) {
[self EndGame];
}
if (CGRectIntersectsRect(Heli.frame, Bottom1.frame)) {
[self EndGame];
}
if (CGRectIntersectsRect(Heli.frame, Top1.frame)) {
[self EndGame];
}
}
-(void)EndGame{
if (Scorenumber > HighScore) {
HighScore = Scorenumber;
[[NSUserDefaults standardUserDefaults] setInteger:HighScore
forKey:#"HighScoreSaved"];
}
Heli.hidden = YES;
[timer invalidate];
[Scorer invalidate];
[self performSelector:#selector(NewGame) withObject: nil afterDelay:2];
}
-(void)NewGame{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
// For iPhone
Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Heli.hidden = NO;
Heli.center = CGPointMake(88, 286);
Heli.image = [UIImage imageNamed:#"buss til app opp.png"];
Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:#"Score: 0"];
Intro3.text = [NSString stringWithFormat:#"HighScore: %i", HighScore];
}
} else{
// For iPad
Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Heli.hidden = NO;
Heli.center = CGPointMake(153, 515);
Heli.image = [UIImage imageNamed:#"buss til app opp.png"];
Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:#"Score: 0"];
Intro3.text = [NSString stringWithFormat:#"HighScore: %i", HighScore];
Just look at following code:
-(void)NewGame{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
// For iPhone
Bottom1.hidden = YES;
Top1.hidden = YES;
Obstacle.hidden = YES;
Obstacle2.hidden = YES;
corona.hidden = YES;
Intro1.hidden = NO;
Intro2.hidden = NO;
Intro3.hidden = NO;
Heli.hidden = NO;
Heli.center = CGPointMake(88, 286);
Heli.image = [UIImage imageNamed:#"buss til app opp.png"];
Start = YES;
Scorenumber = 0;
Score.text = [NSString stringWithFormat:#"Score: 0"];
Intro3.text = [NSString stringWithFormat:#"HighScore: %i", HighScore];
}
} else{
and see - "}" symbol on line before "} else{" is wrong. It is the pair for
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
opening construction, so "else" is "standalone - it is wrong.
Try to delete this "}".
For some reason game center matchMaking works well when both devices on the same wifi but does not work when one of the devices is on 3g (the devices keep searching and cannot find each other).
I am using:
1. iPad 2 with iOS 7.0.4 with sandbox account (compatible to the device's app store account)
2. Iphone 4s with iOS 7.0.4 with sandbox account (compatible to the device's app store account but different from the iPad account).
The code that create the match goes like this:
- (IBAction)continueButtonPressed:(id)sender {
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 4;
request.defaultNumberOfPlayers = 2;
if(([[self.gameTypeSegmentControl objectAtIndex:0] selectedSegmentIndex] == 0) ||
([[self.gameTypeSegmentControl objectAtIndex:1] selectedSegmentIndex] == 0))
{
int temp = [self.allLanguages indexOfObject:[[self.languages objectAtIndex:selectedRow] primaryLanguage]];
if ((temp > 0) && (temp <= self.allLanguages.count))
{
request.playerGroup = temp;
}else
{
request.playerGroup = ENGLISH_US_LANG;//50
}
}
if(([[self.gameTypeSegmentControl objectAtIndex:0] selectedSegmentIndex] == 1) ||
([[self.gameTypeSegmentControl objectAtIndex:1] selectedSegmentIndex] == 1))
{
request.playerGroup = 255;
}
if (isJoining)// Not the creator of the game
{
request.playerAttributes = JOIN_ATTRIBUTE;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error)
{
NSLog(#"findMatchForRequest ended with error");
// Process the error.
}
else if (match != nil)
{
self.myMatch = match; // Use a retaining property to retain the match.
match.delegate = self;
if (!self.matchStarted && match.expectedPlayerCount == 0)
{
self.matchStarted = YES;
NSLog(#"match begin");
// Insert game-specific code to begin the match.
}
}
}];
}else //The creator of the game
{
request.playerAttributes = CREATE_ATTRIBUTE;
GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request];
mmvc.matchmakerDelegate = self;
[self presentViewController:mmvc animated:YES completion:nil];
}
}
Any idea what causing the problem???